I have a datebox user control in grid view and one of the properties is RowID. From Gridview I am passing the Row ID to the datebox as
<uc2:datePage1 ID="txtSubToSA" RowID=<%# Container.DataItemIndex %> runat="server" Enabled="true" Text= '<%#Eval("SUBMITTED_TO_SA") %>' />
in the pageload of the usercontrol I am adding attribute to call a javascript function like this:
protected void Page_Load(object sender, EventArgs e)
{
txtDate.Attributes.Add("onchange", "getRow(" + RowID + ")");
}
public int RowID
{
get;
set;
}
Now when I make a change in the datebox of the gridview, no matter what row it is it always gives takes RowID of 0 and do not recognize changes I made in other rows. What is it that I am doing wrong here?
You’re adding the
onchangeattribute in theLoadevent handler, before theRowIdhas been set – which will happend during databinding. You could perhaps overrideDataBindand set the attribute after databinding is complete: