如何从asp.net C#中的GridView中提取行 [英] How to extract rows from gridview in asp.net c#

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

问题描述

我创建了保存在会话&中的数据表分配给gridview.我必须提取这些记录,为此我编写了如下代码,但其给定值为null:

I have created datatable kept in session & assigned to gridview.I have to extract those records ,for that i have written code as follows but its giving value as null :

//To find gridview in Formview1
    GridView GridView1 = (GridView)Formview1.FindControl("GridView1");
    GridView1.DataSource = (DataTable)Session["tabdetails"];
    GridView1.DataBind();

    string str, str1, str2, str3, str4, str5, str6;
    for (int i = 0; i < GridView1.Rows.Count; i++)
    {
        str = GridView1.Rows[i].Cells[0].Text;
        str1 = GridView1.Rows[i].Cells[1].Text;
        str3 = GridView1.Rows[i].Cells[2].Text;
        str4 = GridView1.Rows[i].Cells[3].Text;
        str5 = GridView1.Rows[i].Cells[4].Text;
    }

请建议我进行正确的更改?谢谢你.Asp.net C#

Please suggest me to do right changes? Thank you. Asp.net c#

推荐答案

使用数据键存储您需要检索的值.

Use data keys to store the values that you need to retrieve.

<asp:GridView ID="GridView1" runat="server" DataKeyNames="SomeColumnName, AnotherColumnName, SomeOtherColumnName" ... >

在后面的代码中:

for (int i = 0; i < GridView1.Rows.Count; i++)
{
    GridViewRow row = GridView1.Rows[i];
    string str = GridView1.DataKeys[row.RowIndex]["SomeColumnName"];
}

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

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