Sathya
Sathya

Reputation: 59

Gridview hyperlink

My first Page :

.aspx

<asp:GridView ID="GridView1" runat="server" BackColor="White" 
       BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" 
       CssClass="grdDataGrid" Height="102px" onrowdatabound="GridView1_RowDataBound"> 
   <RowStyle ForeColor="#000066" /> <FooterStyle BackColor="White" ForeColor="#000066" />
   <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
   <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
   <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" /> 
</asp:GridView>

code behind

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        var firstCell = e.Row.Cells[0];
        firstCell.Controls.Clear();
        firstCell.Controls.Add(new HyperLink { NavigateUrl = "ser_job_status1.aspx?Complaint_No = " + firstCell.Text, Text = firstCell.Text, Target = "_blank" });
        Session["Complaint_No"] = firstCell.Text;
        //////Session["Complaint_No"] = GridView1.Rows[e.RowIndex].Cells[HyperLink(NavigateUrl)].Value.ToString();

      }
 }
GridView1.DataBind();

My second page :

protected void Page_Load(object sender, EventArgs e)
{     
   string strComplaintNo = Convert.ToString(Session["Complaint_No"]);
   TextBox51.Text = strComplaintNo;
}

My Question is since i have use Hyperlink before Binding Datasource to Gridview my firstCell.
Text value holds last fetched data.
So if i click on that link my sessoin get the value of firstCell.
Text which is inturn last fetched value.. But my requirement is to fetch the hyperlinked value..
can anyone help me to solve this issue I have used C# as my code behind...

Upvotes: 2

Views: 416

Answers (2)

शेखर
शेखर

Reputation: 17604

Here is the solution.
As you are sending value through the query string to the next page.
You can set the value there.

protected void Page_Load(object sender, EventArgs e)
{
    string strComplaintNo = Request.QueryString.Get("Complaint_No");
    Session["Complaint_No"]=strComplaintNo ;
    TextBox51.Text = strComplaintNo ;
}

Edit 1

<asp:TemplateField HeaderText="Request No.">
   <ItemTemplate>
       <asp:HyperLink ID="EditHyperLink1" runat="server" 
            NavigateUrl='<%#"ser_job_status1.aspx?reqid=" + Eval("ReqId") %>'
            Text='<%# Eval("ReqId") %>' >
       <!--change the column name "ReqId"-->
       </asp:HyperLink>
   </ItemTemplate>
</asp:TemplateField>

And on your ser_job_status1.aspx page

protected void Page_Load(object sender, EventArgs e)
{
    string strComplaintNo = Request.QueryString.Get("reqid");
    //call your method on the basis of strComplaintNo
   // Session["Complaint_No"]=strComplaintNo ;
    //TextBox51.Text = strComplaintNo ;
}

Upvotes: 0

Abdulrahman_88
Abdulrahman_88

Reputation: 560

give each hyperlink an id in each row depnds on row index,

HyperLink HLLink = GridView1.Rows[e.RowIndex].FindControl("HyperLink"+e.RowIndex) as  HyperLink;

Session["Complaint_No"]=HLLink.NavigateURL.ValueToString();

Upvotes: 1

Related Questions