I did a sample for :
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="false"OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="Start Date">
<ItemTemplate>
<asp:Label runat="server" ID="Label1" Text='<%# Eval("StartDate") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="TextBox1" Text='<%# Eval("StartDate","{0:d}") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="End Date">
<ItemTemplate>
<asp:Label runat="server" ID="Label2" Text='<%# Eval("EndDate") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="TextBox2" Text='<%# Eval("EndDate","{0:d}") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="true" />
</Columns>
</asp:GridView>
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowState == DataControlRowState.Edit)
{
CompareValidator cv = new CompareValidator();
e.Row.Cells[1].Controls.Add(cv);
cv.ControlToValidate = "TextBox2";
cv.Type = ValidationDataType.Date;
cv.Operator = ValidationCompareOperator.GreaterThan;
cv.ErrorMessage = "End date should be later than start date!";
cv.ValueToCompare = ((TextBox)e.Row.FindControl("TextBox1")).Text;
}
}
You can change index or anything as your real situation.
refer from asp.net forum
No comments:
Post a Comment
If any doubt?then please comment in my post