[RESOLVED] Hyperlink in GridView
I am having HyperLink in Gridview, On Hyperlink Click, I am opening new aspx form. Hyperlink Text is Dates,I want to Apply validation. I want that if the hyperlink Text is MAX Date only then the new form will open, else new form will not open. How to do dat??
Code:
<asp:TemplateField HeaderText="Eff Date" SortExpression="EFF_DATE" HeaderStyle-CssClass="GridHeaderStyle">
<ItemTemplate>
<asp:HyperLink ID="HyperLinkEff_Date" runat="server" NavigateUrl='<%# "Rate Master Popup ML.aspx?Rate_ID=" + DataBinder.Eval(Container.DataItem,"RATE_ID") + "&Operation=Edit" + "&Eff_Date=" + DataBinder.Eval(Container.DataItem,"EFF_DATE")%>'
Text='<%# Eval("EFF_DATE","{0:dd/MM/yyyy}") %>' ></asp:HyperLink>
Re: Hyperlink in GridView
Hello Its done.
Try this,
Example:
---------
Code:
<asp:LinkButton id="lnk" runat="server" Text='<%# Eval("EFF_DATE","{0:dd/MM/yyyy}") %>' CommandArgument='<%# "Rate_ID=" + DataBinder.Eval(Container.DataItem,"RATE_ID") + "&Operation=Edit" + "&Eff_Date=" + DataBinder.Eval(Container.DataItem,"EFF_DATE")%>' onClick="lnk_Click"></asp:LinkButton>
In code behind.,
Code:
protected void lnk_Click(object sender,EventArgs e)
{
LinkButton lnkResult = (LinkButton)sender;
string para = lnkResult.CommandArgument.ToString();
DateTime dt = Convert.ToDateTime(lnkResult.Text);
if(dt>DateTime.Now)
{
Response.Redirect("Rate Master Popup ML.aspx?"+para);
}
instead of below code,
Code:
<asp:HyperLink ID="HyperLinkEff_Date" runat="server" NavigateUrl='<%# "Rate Master Popup ML.aspx?Rate_ID=" + DataBinder.Eval(Container.DataItem,"RATE_ID") + "&Operation=Edit" + "&Eff_Date=" + DataBinder.Eval(Container.DataItem,"EFF_DATE")%>'
Text='<%# Eval("EFF_DATE","{0:dd/MM/yyyy}") %>' ></asp:HyperLink>
}
Re: [RESOLVED] Hyperlink in GridView
sonia.sardana,
I think I mentioned this to you in another thread, but just in case...
I would strongly recommend that you don't do all that work in the server side script tags, directly in your ASPX. This blurs the lines between your client and server side code, and makes it difficult to maintain. Put this code in the server side code behind file where it belongs.
Gary