2

我的第一页:

.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>

后面的代码

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();

我的第二页:

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

我的问题是因为我在将数据源绑定到我的 firstCell 之前使用了超链接。
文本值保存最后获取的数据。
因此,如果我单击该链接,我的 sessoin 将获得 firstCell 的值。
文本是最后一次获取的值..但我的要求是获取超链接值..
任何人都可以帮我解决这个问题我使用 C# 作为我背后的代码...

4

2 回答 2

1

根据行索引,在每行中为每个超链接提供一个 id,

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

Session["Complaint_No"]=HLLink.NavigateURL.ValueToString();
于 2013-02-25T06:17:30.683 回答
0

这是解决方案。
当您通过查询字符串将值发送到下一页时。
您可以在那里设置值。

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

编辑 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>

在您的ser_job_status1.aspx页面上

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 ;
}
于 2013-02-25T06:16:31.810 回答