GridView with javascript calender
-
Hello everybody, I have a gridview where a textbox column is present.I have another column which contain a javascript calender. My gridview is dynamically generated. I want to assign the textbox value through the calender. My gridview code is as below CellSpacing="2" CssClass="text" ForeColor="#333333" GridLines="None" PageSize="4" Width="600px" OnRowDataBound="GrdSubs_RowDataBound"> ForeColor="#333333" /> runat="server" type="checkbox" />
-
Hello everybody, I have a gridview where a textbox column is present.I have another column which contain a javascript calender. My gridview is dynamically generated. I want to assign the textbox value through the calender. My gridview code is as below CellSpacing="2" CssClass="text" ForeColor="#333333" GridLines="None" PageSize="4" Width="600px" OnRowDataBound="GrdSubs_RowDataBound"> ForeColor="#333333" /> runat="server" type="checkbox" />
When a textbox column of a
GridView
is written out to the browser, the Id's of the text boxes are generated automatically by ASP.NET. The solution to your problem is letting the javascript calendar know the id of the textbox sitting next to it, in the same row of the grid. You can do this in theRowDataBound
event of theGridView
which is fired as the data for each row of the GridView is bound.protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// Access textbox here and assign onclick ...
}
}Once you access the TextBox you can assign the onclick event to it with the appropriate client side textbox Id.
myTextBox.Attributes\["onclick"\] = "popUpCalendar(this, " + myTextBox.ClientId + ", \\"dd/mm/yyyy\\")";
Use the
ClientId
property on the server side to get the id of the textbox which will be written to the browser for that particular row. By examining the source of the web page you will see that the onclick for each row will have the correct id for the associated textbox.Declan Bright www.declanbright.com