从asp.net vb中的gridview检索数据

时间:2014-03-26 07:20:53

标签: asp.net vb.net gridview

我一直在寻找这一段时间,但我仍然不知道如何从Asp.net vb中的Gridview中获取所选路由中的数据。

我试过这个,但后来我明白了:对象引用未设置为对象的实例。

Dim email As String
email = Gridview1.SelectedRow.Cells(1).Text

4 个答案:

答案 0 :(得分:0)

您必须先调用DataBind:

Gridview1.DataBind();
Dim email As String
email = Gridview1.SelectedRow.Cells(1).Text

答案 1 :(得分:0)

试试这个......

email = GridView1.CurrentRow.Cells(1).Value.ToString()

答案 2 :(得分:0)

试试这个,它可能会起作用

Dim email As String
email = Gridview1.SelectedRow.Cells(1).Value.ToString()

答案 3 :(得分:0)

protected void OnSelectedIndexChanged(object sender, EventArgs e)
{
    //Accessing BoundField Column
    string name = GridView1.SelectedRow.Cells[0].Text;

    //Accessing TemplateField Column controls
    string country = (GridView1.SelectedRow.FindControl("lblCountry") as Label).Text;

    lblValues.Text = "<b>Name:</b> " + name + " <b>Country:</b> " + country;
}

请参阅以下链接。

http://www.aspsnippets.com/Articles/How-to-get-Selected-Row-cell-value-from-GridView-in-ASPNet.aspx