This is very easy to integrate a GridView control to Java Script Calender Control.
The code will be looking like this in GridView template.
In the gridview control every row in the grid view return the diffrent id for the calender control. We need to catch the calender id at runtime.
<asp:TemplateField SortExpression="Purchase_Dt" HeaderText="Purchase Date">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Wrap="False"/>
<EditItemTemplate>
<asp:TextBox ID="txt_Purchase_Dt" Width="100" Runat="server" Text='<%# Bind("Purchase_Dt","{0:dd/MM/yyyy}") %>'></asp:TextBox><asp:ImageButton ID="img_date" CommandName="img_date1" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" ImageUrl="~/cal.gif" runat="server" />
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtPurchase_Dt" runat="server" Width="100"></asp:TextBox><asp:ImageButton ID="img_date_Footer" CommandName="img_date_Footer" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" ImageUrl="~/cal.gif" runat="server" />
</FooterTemplate>
<ItemTemplate>
<asp:Label Runat="server" Text='<%# Bind("Purchase_Dt","{0:dd/MM/yyyy}") %>' ID="lbl_Purchase_Dt"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Then open the RowDataItem event of the Gridview control here we can get the ID of the calender control at runtime in grid view control.
The code looking like this.
protected void g1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowState == DataControlRowState.Edit || (e.Row.RowState == (DataControlRowState.Edit | DataControlRowState.Alternate)))
{
ImageButton i1 = (ImageButton)e.Row.FindControl("img_date");
TextBox t1 = (TextBox)e.Row.FindControl("txt_Purchase_Dt");
i1.Attributes.Add("OnClick", "return f1(" + t1.ClientID + ")");
}
else if (e.Row.RowType== DataControlRowType.Footer)
{
if (e.Row.RowState == DataControlRowState.Normal)
{
ImageButton i1 = (ImageButton)e.Row.FindControl("img_date_Footer");
TextBox t1 = (TextBox)e.Row.FindControl("txtPurchase_Dt");
i1.Attributes.Add("OnClick", "return f1(" + t1.ClientID + ")");
LinkButton L2 = (LinkButton)e.Row.Cells[0].FindControl("LinkButton2");
TextBox txt_AvalidQnty = (TextBox)e.Row.FindControl("txtLic_Avlbl_qty");
TextBox txt_PurDate = (TextBox)e.Row.FindControl("txtPurchase_Dt");
TextBox txt_SoftDesc = (TextBox)e.Row.FindControl("txtSoftware_Desc");
//TextBox t3 = (TextBox)e.Row.FindControl("txt_Lic_Avlbl_qty");
L2.Attributes.Add("OnClick", "return Validate(" + txt_SoftDesc.ClientID + "," + txt_PurDate.ClientID + "," + txt_AvalidQnty.ClientID + ")");
//TextBox txt_PurDate = (TextBox)e.Row.FindControl("txtPurchase_Dt");
//L2.Attributes.Add("OnClick", "return Validate_PurchaseDate(" + txt_PurDate.ClientID + ")");
//TextBox txt_SoftDesc = (TextBox)e.Row.FindControl("txtSoftware_Desc");
//L2.Attributes.Add("OnClick", "return Validate_SoftDesc(" + txt_SoftDesc.ClientID + ")");
}
}
The java function f1 code is following:
function f1(Object)
{
//alert(Object);
showCalendarControl(Object);
return false;
}
This function is the java script calender control
showCalendarControl(Object);
This is the code I have written in my application.
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.
Gowtham RajamanickamPosted Apr 12, 2016, 2:17 AM
Good One, Thanks for sharing
Abhijeet SinhaPosted May 10, 2010, 2:08 AM
its not working
MohammedPosted Jun 2, 2009, 1:39 AM
nice work but u may save time and effort instead of doing coding on row data bind you may use 2 options: 1) use Microsoft Ajax Calender extender control 2) in case you don't like option 1 you may use jQuery and date time picker plugin or any Calender plugins and mark required textbox control with specific Css Class that mapped with jquery plugin.
waqar laghariPosted May 11, 2009, 1:29 AM
Dear brother's, This article is very good and very helpful to me. thanks brother to share a great knowlodge. I hope you will keep it.