Results 1 to 3 of 3

Thread: [RESOLVED] Hyperlink in GridView

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2008
    Posts
    474

    Resolved [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>

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2008
    Posts
    474

    Re: Hyperlink in GridView

    Hello Its done.
    Try this,

    Example:
    ---------
    Code:
    <asp:LinkButton id="lnk" runat="server" Text='<&#37;# 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>
    }

  3. #3
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width