如何在GridView中获取行值 [英] how to get row value in gridview

查看:70
本文介绍了如何在GridView中获取行值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个Gridview1.在其第一列中有employee_id.我如何在单击按钮时获取该员工ID ...

Hi,
I have a Gridview1. In its first column there is employee_id. How can i get that employee id on button click...

推荐答案

您好

请在您的gridview中添加此按钮列

Hi

Please add this button colum in your gridview

<Columns>

      <asp:TemplateField HeaderText="CurriculumID" HeaderStyle-ForeColor="White">

         <ItemTemplate>
         <asp:Button ID="lblemployee_id" runat="server" CausesValidation="True"

         PostBackUrl='<%#"WebPageName.aspx?EmployeeID=" + HttpUtility.UrlEncode(Eval("employee_id").ToString())%>' Text="Employee ID></asp:Button>
         </ItemTemplate>
         <ItemStyle HorizontalAlign="Center" />

</Columns>




当您单击按钮时,它将获得您的ID并将其传递给您选择的WebPageName.aspx.

现在,下面将是您的WebPageName.aspx的背面代码.




When you click the button it will get your ID and pass it to your WebPageName.aspx of your choice.

Now Below will be the back code of your WebPageName.aspx

 protected void Page_Load(object sender, EventArgs e)
        {

if (Request.QueryString["EmployeeID"] != null && !string.IsNullOrEmpty(Request.QueryString["EmployeeID"].ToString()))
            {
                Session["EmployeeID"] = Request.QueryString["EmployeeID"].ToString();

                MessageBox.Show(Session["EmployeeID"].String(),"");
            }
        }



希望对您有帮助...



Hope it helps...


在单击按钮时调用javscript功能
将以下代码写入您的javascript函数


call javscript fuction on button click
write following code to your javascript function


var gdv = document.getElementById('Gridview1');

for (var i = 0; i < gdv.rows.length-1; i++) {

    var empId=gdv.rows(i).cells(0).innerHTML;
    alert(empId);
}



希望对您有帮助.



i hope it helps you.


您好,

尝试检查以下链接:

http://stackoverflow.com/questions/8829490/get-value-from- asp-net-gridview-cell [ ^ ]

http://forums.asp.net/p/1190105/2041616.aspx [ ^ ]

问候
罗伯特
Hi,

try to check following links:

http://stackoverflow.com/questions/8829490/get-value-from-asp-net-gridview-cell[^]

http://forums.asp.net/p/1190105/2041616.aspx[^]

Regards
Robert


这篇关于如何在GridView中获取行值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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