Showing posts with label create. Show all posts
Showing posts with label create. Show all posts

Saturday, March 31, 2012

Set a bgcolor in a repeater based on databse value asp newbie

Hi,

I'm just starting to write in asp and have been trying to create a repeater
to display some data in a simple form.

The basics worked ok and then I tried to set a bgcolor on a cell based on
it's value, I have read and re-read a good few things but nothing seems to
point to this scenario directly. I know the following code doesn't actually
work but this is roughly what I'm trying to do. eventually I want to do the
same thing with dates but baby steps first :)

<ItemTemplate>
<%If #(DataBinder.Eval(Container.DataItem, "CategoryName") =
"something") Then%>'
<tr>
<td bgcolor="#ff0000">
<%Else%>
<tr>
<td bgcolor="#CCFFCC">
<% End If%>
<asp:Label runat="server" ID="Labell" Text='<%#
Eval("CategoryName") %>' />
</td>
<td bgcolor="#CCFFCC">
<asp:Label runat="server" ID="Label2" Text='<%#
Eval("Description") %>' />
</td>
</tr>
</ItemTemplate
Thanks in advance for any help

Jim FlorenceInstead of attempting to change the colour of the <ItemTemplate>, add an
<AlternatingItemTemplate> section and type the colour in there. dotNet will
then take care of the rest for you.

"Jim Florence" wrote:

> Hi,
> I'm just starting to write in asp and have been trying to create a repeater
> to display some data in a simple form.
> The basics worked ok and then I tried to set a bgcolor on a cell based on
> it's value, I have read and re-read a good few things but nothing seems to
> point to this scenario directly. I know the following code doesn't actually
> work but this is roughly what I'm trying to do. eventually I want to do the
> same thing with dates but baby steps first :)
> <ItemTemplate>
> <%If #(DataBinder.Eval(Container.DataItem, "CategoryName") =
> "something") Then%>'
> <tr>
> <td bgcolor="#ff0000">
> <%Else%>
> <tr>
> <td bgcolor="#CCFFCC">
> <% End If%>
> <asp:Label runat="server" ID="Labell" Text='<%#
> Eval("CategoryName") %>' />
> </td>
> <td bgcolor="#CCFFCC">
> <asp:Label runat="server" ID="Label2" Text='<%#
> Eval("Description") %>' />
> </td>
> </tr>
> </ItemTemplate>
> Thanks in advance for any help
> Jim Florence
"Dean" <Dean@.discussions.microsoft.com> wrote in message
news:79F7A0BD-A3ED-4605-8CE4-89DACF298D04@.microsoft.com...
Dean,

Thanks for the reply, that works great for the entire row but not for
individual cells within the row based on the cell's value or name.

What I'm eventually trying to do is set an individual date cell to be either
red, amber or green depending on how many days overdue an item is

Many thanks again

Jim

>Instead of attempting to change the colour of the <ItemTemplate>, add an
> <AlternatingItemTemplate> section and type the colour in there. dotNet
> will
> then take care of the rest for you.
>
> "Jim Florence" wrote:
>>
>> Hi,
>>
>> I'm just starting to write in asp and have been trying to create a
>> repeater
>> to display some data in a simple form.
>>
>> The basics worked ok and then I tried to set a bgcolor on a cell based on
>> it's value, I have read and re-read a good few things but nothing seems
>> to
>> point to this scenario directly. I know the following code doesn't
>> actually
>> work but this is roughly what I'm trying to do. eventually I want to do
>> the
>> same thing with dates but baby steps first :)
>>
>> <ItemTemplate>
>> <%If #(DataBinder.Eval(Container.DataItem, "CategoryName") =
>> "something") Then%>'
>> <tr>
>> <td bgcolor="#ff0000">
>> <%Else%>
>> <tr>
>> <td bgcolor="#CCFFCC">
>> <% End If%>
>> <asp:Label runat="server" ID="Labell" Text='<%#
>> Eval("CategoryName") %>' />
>> </td>
>> <td bgcolor="#CCFFCC">
>> <asp:Label runat="server" ID="Label2" Text='<%#
>> Eval("Description") %>' />
>> </td>
>> </tr>
>> </ItemTemplate>
>>
>> Thanks in advance for any help
>>
>> Jim Florence
>>
Jim,

Try this instead:
<td bgcolor='<%#(DataBinder.Eval(Container.DataItem, "CategoryName") ==
"something"?"#ff0000":"#ffffff"%>'
This assumes that you are in C#, in VB i think there is a immediate if
of IIf();

HTH,
Chris
"chris" <chris@.cubed-c.com> wrote in message
news:1151142480.516385.115290@.m73g2000cwd.googlegr oups.com...
Chris your a star,

After very minor fiddling the code is

<td bgcolor='<%# IIF (DataBinder.Eval(Container.DataItem, "CategoryName") =
"Confections","#ff0000","#ccffcc")%>'
Thanks very much for your help I tearing my hair out trying to make this
work

Regards

Jim

> Jim,
> Try this instead:
> <td bgcolor='<%#(DataBinder.Eval(Container.DataItem, "CategoryName") ==
> "something"?"#ff0000":"#ffffff"%>'>
> This assumes that you are in C#, in VB i think there is a immediate if
> of IIf();
> HTH,
> Chris

set an event in a ListBox in runtime

I want to create a ListBox in runtime

dim objCoun as new listbox
objCoun.id = "lbxCountries"
objCoun.Rows = "1"
objCoun.DataTextField = "Country_Name"
objCoun.DataValueField = "Country_Id"

But when I try to set the event

objCoun.OnSelectedIndexChanged="tro"

This is the error message:

Compiler Error Message: BC30390: 'System.Web.UI.WebControls.ListControl.Protected Overridable Sub OnSelectedIndexChanged(e As System.EventArgs)' is not accessible in this context because it is 'Protected'.

Source Error:

Line 44: objCoun.DataTextField = "Country_Name"
Line 45: objCoun.DataValueField = "Country_Id"
Line 46: objCoun.OnSelectedIndexChanged = "tro"
Line 47: objCoun.DataSource=dbread
Line 48: objCoun.DataBind()

How can I set the event in runtime?

Thanks for your helpTry:


AddHandler objCoun.SelectedIndexChanged, AddressOf tro

...assuming tro is the name of your event handler with the appropriate signature:

Private Sub tro(ByVal sender As System.Object, ByVal e As System.EventArgs)

"tro" is the subroutine name. That means when the objCoun changes its index then the action is sent to "tro"

Set ASPNET Version for Virtual Directory from C# App

I am writing a C# Windows Application that will create virtual directories o
n
our Win 2003 server machines. Using the System.DirectoryServices
DirectoryEntry class I have had very little trouble remotely creating and
configuring virtual directories on our servers. My problem is that I have
not found a way to remotely configure the version of ASPNET that will be use
d
by the application running in the virtual directories I create. We have a
mix of Web applications that require either version 1.1 or 2.0. The only wa
y
that I have found to manipulate ASPNET setting, other than doing it manually
through IIS Manager, is with the ASPNET_regiis.exe tool, which must be run o
n
the machine that is serving the virtual directory. Is there any way to set
a
virtual directory's ASPNET version remotely?
Mikere:
!> The only way that I have found to manipulate ASP.NET setting, other than
doing it
!> manually through IIS Manager, is with the ASPNET_regiis.exe tool, which m
ust be
!> run on the machine that is serving the virtual directory.
Right...
re:
!> Is there any way to set a virtual directory's ASP.NET version remotely?
Not that I know of.
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
======================================
"mikes" <mikes@.discussions.microsoft.com> wrote in message news:8F4530DF-4CAA-4A93-A19E-53B
AECAF5432@.microsoft.com...
>I am writing a C# Windows Application that will create virtual directories
on
> our Win 2003 server machines. Using the System.DirectoryServices
> DirectoryEntry class I have had very little trouble remotely creating and
> configuring virtual directories on our servers. My problem is that I have
> not found a way to remotely configure the version of ASPNET that will be u
sed
> by the application running in the virtual directories I create. We have a
> mix of Web applications that require either version 1.1 or 2.0. The only
way
> that I have found to manipulate ASPNET setting, other than doing it manual
ly
> through IIS Manager, is with the ASPNET_regiis.exe tool, which must be run
on
> the machine that is serving the virtual directory. Is there any way to se
t a
> virtual directory's ASPNET version remotely?
> Mike

Set ASPNET Version for Virtual Directory from C# App

I am writing a C# Windows Application that will create virtual directories on
our Win 2003 server machines. Using the System.DirectoryServices
DirectoryEntry class I have had very little trouble remotely creating and
configuring virtual directories on our servers. My problem is that I have
not found a way to remotely configure the version of ASPNET that will be used
by the application running in the virtual directories I create. We have a
mix of Web applications that require either version 1.1 or 2.0. The only way
that I have found to manipulate ASPNET setting, other than doing it manually
through IIS Manager, is with the ASPNET_regiis.exe tool, which must be run on
the machine that is serving the virtual directory. Is there any way to set a
virtual directory's ASPNET version remotely?

Mikere:
!The only way that I have found to manipulate ASP.NET setting, other than doing it
!manually through IIS Manager, is with the ASPNET_regiis.exe tool, which must be
!run on the machine that is serving the virtual directory.

Right...

re:
!Is there any way to set a virtual directory's ASP.NET version remotely?

Not that I know of.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
======================================
"mikes" <mikes@.discussions.microsoft.comwrote in message news:8F4530DF-4CAA-4A93-A19E-53BAECAF5432@.microsoft.com...

Quote:

Originally Posted by

>I am writing a C# Windows Application that will create virtual directories on
our Win 2003 server machines. Using the System.DirectoryServices
DirectoryEntry class I have had very little trouble remotely creating and
configuring virtual directories on our servers. My problem is that I have
not found a way to remotely configure the version of ASPNET that will be used
by the application running in the virtual directories I create. We have a
mix of Web applications that require either version 1.1 or 2.0. The only way
that I have found to manipulate ASPNET setting, other than doing it manually
through IIS Manager, is with the ASPNET_regiis.exe tool, which must be run on
the machine that is serving the virtual directory. Is there any way to set a
virtual directory's ASPNET version remotely?
>
Mike

Thursday, March 29, 2012

Set Column Headertext

Hi
I have a Datagrid with a templatecolumn, where I add at design time. I also checked the "create columns automatically"
I would like to change the headertext of columns created automatically, but i don't know in which event I can do that

Can you help me

P.S. I tryied to set the headertext in the "PreRender" event of the DataGrid, but in this point the grid has still only the templatecolumn, and the others columns aren't created yet

Thank you
Alessandro RossHi, Alessandro Rossi,

If you extend the DataGrid class (inherit from it) the best place is the
OnDataBinding protected method. You should first call base.OnDataBinding(e);
of course.

If you are simply using the DataGrid class - set the headertexts after you
call DataBind() because the columns are in fact created with this call.

Hope this helps
Martin
"Alessandro Rossi" <alessandro.rossi@.areait.net> wrote in message
news:528CD483-7F36-4D2A-8760-24CD36F0BE8A@.microsoft.com...
> Hi,
> I have a Datagrid with a templatecolumn, where I add at design time. I
also checked the "create columns automatically".
> I would like to change the headertext of columns created automatically,
but i don't know in which event I can do that.
> Can you help me?
> P.S. I tryied to set the headertext in the "PreRender" event of the
DataGrid, but in this point the grid has still only the templatecolumn, and
the others columns aren't created yet.
> Thank you.
> Alessandro Rossi

Saturday, March 24, 2012

Set Focus on txt box within an user control

I am try to find a way to set focus on the txt box that is in an user control I create, any ideas about this?

ThanksYou can do this using Javascript.

Thanks,
Sridhar!!
Thanks, How? this text box is in the user control, I know how to use JavaScript to set Focus if the control is a server control but not this one.
You just need to make sure that you use the full client ID of the textbox. You could do this by hard-coding the ID of the user control appended to the ID of the textbox, or you could just get the ClientID of the textbox and pass that to your client script.
Hi Penghao98,

How about usingthis control from Meta builders which will essentially write javascript for you :)

HTH
Thanks, do you think you can give me a little example of it?
Hmm. I am not really for using a third party control, for as simple as this. You should identify your textbox inside the user control (in javascript) and set the focus after the page has loaded.

Lets say your user control id is "uc1"
and id of the textbox inside the "uc1" user control is "txt1"

You should be able to set the focus as

document.getElementById("uc1:txt1").focus();

Remember to place this code after the controls on the form has been loaded. May be after the closing form tag "</form>" in the html
Actually, I believe that would be

document.getElementById("uc1_txt1").focus();

(note the underscore instead of colon)
Yeah Peter is correct it should be

document.getElementById("uc1_txt1").focus();
oops. Sorry for the mistake. It should be underscore. Thanks for correcting me guys
Check out this :view post 821121

regards

Set Focus to control

Hello,
I have a content page (I am using a Master Page) that has a control
"ddlRequestType".
In my code behind, I am using the following to create an image and assign
JavaScript to it that will set the focus to the control "ddlRequestType":
If Trim(Me.ddlRequestType.SelectedItem.Text) = "None Selected" Then
strValidateText &= _
"<tr>" & _
"<td width=200><div align=left>Request Type</div></td>" & _
"<td width=400><div align=left><A HREF=#
ONCLICK=ddlRequestType.focus()>" & _
"<IMG SRC=../../images/art_dbflash_go.jpg BORDER=0 ALT=GoTo>" & _
"</div></td>" & _
"</tr>"
strValidateForm = "Validation Error"
End If
However, when I click on the image, I get the following error:
ddlRequestType is undefined.
Any help with this would be appreciated.
Thanks in advance,
sck10Hi,
Try:
document.getElementById('ddlRequestType').focus(); or
Form1.getElementById('ddlRequestType').focus();
Good luck! Ken.
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.
"sck10" <sck10@.online.nospam> wrote in message
news:OLLy0hGvEHA.3728@.TK2MSFTNGP12.phx.gbl...
> Hello,
> I have a content page (I am using a Master Page) that has a control
> "ddlRequestType".
> In my code behind, I am using the following to create an image and assign
> JavaScript to it that will set the focus to the control "ddlRequestType":
> If Trim(Me.ddlRequestType.SelectedItem.Text) = "None Selected" Then
> strValidateText &= _
> "<tr>" & _
> "<td width=200><div align=left>Request Type</div></td>" & _
> "<td width=400><div align=left><A HREF=#
> ONCLICK=ddlRequestType.focus()>" & _
> "<IMG SRC=../../images/art_dbflash_go.jpg BORDER=0 ALT=GoTo>" & _
> "</div></td>" & _
> "</tr>"
> strValidateForm = "Validation Error"
> End If
>
> However, when I click on the image, I get the following error:
> ddlRequestType is undefined.
> Any help with this would be appreciated.
> --
> Thanks in advance,
> sck10
>
>
I suggest you to don't use direct id or name for referencing javascript
object, try this:
HREF="java script:document.getElementById('ddlRequestType').focus()"
However i tink is better don't use string for create controls, try add
controls using TableCell,TableRow,ImageButton.
This is a simple example:
Dim tempRow as new TableRow()
Dim tempCell as new TableCell()
Dim myButton as new ImageButton
'Assign properties to rows and cell
myButton.attributes("onclick")="document.getElementById('ddlRequestType').fo
cus()"
tempCell.Controls.Add(myButton )
tempRow.Cells.Add(tempCell)
'add your row to your table rows
"sck10" <sck10@.online.nospam> ha scritto nel messaggio
news:OLLy0hGvEHA.3728@.TK2MSFTNGP12.phx.gbl...
> Hello,
> I have a content page (I am using a Master Page) that has a control
> "ddlRequestType".
> In my code behind, I am using the following to create an image and assign
> JavaScript to it that will set the focus to the control "ddlRequestType":
> If Trim(Me.ddlRequestType.SelectedItem.Text) = "None Selected" Then
> strValidateText &= _
> "<tr>" & _
> "<td width=200><div align=left>Request Type</div></td>" & _
> "<td width=400><div align=left><A HREF=#
> ONCLICK=ddlRequestType.focus()>" & _
> "<IMG SRC=../../images/art_dbflash_go.jpg BORDER=0 ALT=GoTo>" & _
> "</div></td>" & _
> "</tr>"
> strValidateForm = "Validation Error"
> End If
>
> However, when I click on the image, I get the following error:
> ddlRequestType is undefined.
> Any help with this would be appreciated.
> --
> Thanks in advance,
> sck10
>
>

Set Focus to control

Hello,

I have a content page (I am using a Master Page) that has a control
"ddlRequestType".

In my code behind, I am using the following to create an image and assign
JavaScript to it that will set the focus to the control "ddlRequestType":

If Trim(Me.ddlRequestType.SelectedItem.Text) = "None Selected" Then
strValidateText &= _
"<tr>" & _
"<td width=200><div align=left>Request Type</div></td>" & _
"<td width=400><div align=left><A HREF=#
ONCLICK=ddlRequestType.focus()>" & _
"<IMG SRC=../../images/art_dbflash_go.jpg BORDER=0 ALT=GoTo>" & _
"</div></td>" & _
"</tr>"
strValidateForm = "Validation Error"
End If

However, when I click on the image, I get the following error:
ddlRequestType is undefined.

Any help with this would be appreciated.

--
Thanks in advance,

sck10Hi,

Try:

document.getElementById('ddlRequestType').focus(); or
Form1.getElementById('ddlRequestType').focus();

Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"sck10" <sck10@.online.nospam> wrote in message
news:OLLy0hGvEHA.3728@.TK2MSFTNGP12.phx.gbl...
> Hello,
> I have a content page (I am using a Master Page) that has a control
> "ddlRequestType".
> In my code behind, I am using the following to create an image and assign
> JavaScript to it that will set the focus to the control "ddlRequestType":
> If Trim(Me.ddlRequestType.SelectedItem.Text) = "None Selected" Then
> strValidateText &= _
> "<tr>" & _
> "<td width=200><div align=left>Request Type</div></td>" & _
> "<td width=400><div align=left><A HREF=#
> ONCLICK=ddlRequestType.focus()>" & _
> "<IMG SRC=../../images/art_dbflash_go.jpg BORDER=0 ALT=GoTo>" & _
> "</div></td>" & _
> "</tr>"
> strValidateForm = "Validation Error"
> End If
>
> However, when I click on the image, I get the following error:
> ddlRequestType is undefined.
> Any help with this would be appreciated.
> --
> Thanks in advance,
> sck10
I suggest you to don't use direct id or name for referencing javascript
object, try this:
HREF="javascript:document.getElementById('ddlRequestType ').focus()"

However i tink is better don't use string for create controls, try add
controls using TableCell,TableRow,ImageButton.
This is a simple example:

Dim tempRow as new TableRow()
Dim tempCell as new TableCell()
Dim myButton as new ImageButton
'Assign properties to rows and cell
myButton.attributes("onclick")="document.getElementById('ddlRequestType').focus()"
tempCell.Controls.Add(myButton )
tempRow.Cells.Add(tempCell)
'add your row to your table rows

"sck10" <sck10@.online.nospam> ha scritto nel messaggio
news:OLLy0hGvEHA.3728@.TK2MSFTNGP12.phx.gbl...
> Hello,
> I have a content page (I am using a Master Page) that has a control
> "ddlRequestType".
> In my code behind, I am using the following to create an image and assign
> JavaScript to it that will set the focus to the control "ddlRequestType":
> If Trim(Me.ddlRequestType.SelectedItem.Text) = "None Selected" Then
> strValidateText &= _
> "<tr>" & _
> "<td width=200><div align=left>Request Type</div></td>" & _
> "<td width=400><div align=left><A HREF=#
> ONCLICK=ddlRequestType.focus()>" & _
> "<IMG SRC=../../images/art_dbflash_go.jpg BORDER=0 ALT=GoTo>" & _
> "</div></td>" & _
> "</tr>"
> strValidateForm = "Validation Error"
> End If
>
> However, when I click on the image, I get the following error:
> ddlRequestType is undefined.
> Any help with this would be appreciated.
> --
> Thanks in advance,
> sck10

Thursday, March 22, 2012

Set headertext in datagrid programatically

I create a datagrid using the Web Forms Toolbox
The dataadapter,dataset and databind() code runs in a button eventhandler
The headertext is currently determined by the column names of my SQL select
statement there.
How can I change the headertext programatically in the codebehind? ... I do
n't want to change the preexisting code if at all possible.in your itemdatabound event handler, you can test for the headeritem and
then use the text property attached to the cell object to change the text
e.item.cells[4].text = "vapor"
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
"mg" <mg@.theworld.com> wrote in message
news:88A2B342-0B07-4CD5-80AC-8C989FE5C2EA@.microsoft.com...
>I create a datagrid using the Web Forms Toolbox
> The dataadapter,dataset and databind() code runs in a button eventhandler
> The headertext is currently determined by the column names of my SQL
> select statement there.
> How can I change the headertext programatically in the codebehind? ... I
> don't want to change the preexisting code if at all possible.

Set headertext in datagrid programatically

I create a datagrid using the Web Forms Toolbo

The dataadapter,dataset and databind() code runs in a button eventhandler

The headertext is currently determined by the column names of my SQL select statement there

How can I change the headertext programatically in the codebehind? ... I don't want to change the preexisting code if at all possible.in your itemdatabound event handler, you can test for the headeritem and
then use the text property attached to the cell object to change the text
e.item.cells[4].text = "vapor"

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
"mg" <mg@.theworld.com> wrote in message
news:88A2B342-0B07-4CD5-80AC-8C989FE5C2EA@.microsoft.com...
>I create a datagrid using the Web Forms Toolbox
> The dataadapter,dataset and databind() code runs in a button eventhandler
> The headertext is currently determined by the column names of my SQL
> select statement there.
> How can I change the headertext programatically in the codebehind? ... I
> don't want to change the preexisting code if at all possible.

set meta:resourcekey at runtime

Hi,

how do you set the meta:resourcekey of a dynamically generated control? If I create a new label onInit, how do i set "lblTest.Text" to it?

Thanks

Hello,

You can add the Text property and set its value to:

myLabel.Text = GetLocalResourceObject("Label1.Text");

Does this help?

Regards


Cheers :)

This is one of the methods you can use to do the Localization programmatically!

You also have another method for the Global resources as well!

Regards