Click to See Complete Forum and Search --> : How to set attribute to the controls in datagrid?


satees
04-19-2007, 11:55 AM
Hi,

I have datagrid control which contains textboxs in ItemTemplate. I need to set attribute to the textbox for the purpose of accessing the client side java script function.

Here is my code snip.



<asp:TemplateColumn HeaderText="Fld Date">
<ItemTemplate>
<%# (DataBinder.Eval(Container.DataItem,"DATE","{0:d}").ToString()) %>
</ItemTemplate>
<ItemStyle VerticalAlign="Top" />
<EditItemTemplate>
<asp:TextBox id="txtDate" runat="server" /><asp:TextBox id="txtDate" runat="server" />
</EditItemTemplate>
<FooterStyle VerticalAlign="Top" />
</asp:TemplateColumn>



Here i need to set the attribue when edit the datagrid item.
Please help me.

Thanks in advance.

Satees

PeOfEo
04-19-2007, 12:05 PM
On page load:
Textboxid.Attributes("onfocus") = "somefunction(this);"
Textboxid.Attributes("onblur") = "somefunction(this);"

satees
04-19-2007, 12:15 PM
Thanks PeOfEo, but i can't access the textbox id in page load?

I think it can't accessed, coz its datagrid item?

PeOfEo
04-19-2007, 01:25 PM
txtDate is the id of the textbox in your item template. I would have thought if you applied an attribute to that it would affect the other's generated. I don't have time to look into this more right now, but I will try to look into this more later, but if worst comes to worst you can always inherit the textbox class and write in the attribute you need.