row.Cells[4].Text returns nothing in GridView1_SelectedIndexChanged?

后端 未结 3 1222
难免孤独
难免孤独 2021-01-22 02:05

I have a GridView in my page :



        
3条回答
  •  天涯浪人
    2021-01-22 02:22

    There is no Text as your data is stored in controls. You need to search for the control you want and pull the Text out of.

    Eg:

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) 
    { 
        GridViewRow row = GridView1.SelectedRow; 
        string temp = row.Cells[4].FindControl('LabelGridViewBankName').Text; 
        LabelResult.Text = temp; 
    }
    

    Optionally you could could key off the DataKey property if you are using it and then use it to search your datasource for the value you want.

提交回复
热议问题