如何在GridView中将列字段设置为链接 [英] How to set a column field as Link in GridView

查看:65
本文介绍了如何在GridView中将列字段设置为链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在该网格视图中,我有一列包含该人员的姓名.当我单击该名称然后在另一个网格视图中显示人员的详细信息时

In that Grid view I have one column that column contain Name of the person.when I click that name then show the details of person in another grid view

推荐答案

您可以添加模板字段,如下所示:

You can add template field as follows:

<asp:TemplateField>
   <itemtemplate>
                         <asp:linkbutton runat="server" id="lnkName" text="<%# DataBinder.Eval (Container.DataItem, "PersonNameColumnName") %>" commandname="PersonDetail" commandarguement="DataBinder.Eval (Container.DataItem, "IDColumnName") %>" />
    </itemtemplate>
  </asp:templatefield>




然后,您可以处理网格的row命令事件.在其中可以检查命令名称是否为"PersonDetail"?如果是,那么您可以将另一个网格与可以从命令参数中检索其ID的人员的详细信息绑定.




Then you can handle the row command event of grid. Inside which you can check if command name is "PersonDetail"? If yes then you can bind another grid with details of the person whose id can be retrieved from Command Arguement.


<asp:templatefield headertext="User" xmlns:asp="#unknown">
    <itemtemplate>

        <asp:linkbutton runat="server" id="btnGetDetails" commandargument="<%#Eval("ID") %>" commandname="GetDtls" text="<%#Eval("Name") %>" />
    </itemtemplate>
</asp:templatefield>





protected void gvContacts_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if(e.CommmondName=="GetDtls")
    {
        int intContactID =Convert.ToInt32( e.CommandArgument);  //find the user id you want to get details..
        //Do your Get Details logic here based on "intContactID".. 
    }
}


这篇关于如何在GridView中将列字段设置为链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆