1
       protected void GridView1_OnRowCommand(object sender, GridViewCommandEventArgs e)
{
        int index = Convert.ToInt32(e.CommandArgument);
        GridViewRow row = GridView1.Rows[index];

        k = row.Cells[0].ToString();
        Label1.Text = k;
 }

I want to get a value of a particular cell in the selected row.So I tried with this but this is giving very odd result the label printing the below text

     System.Web.UI.WebControls.DataControlFieldCell.

Can anybody tell me how to solve my problem.

Naresh
  • 657
  • 3
  • 16
  • 35

3 Answers3

2

Try this:

k = row.Cells[0].Text;

You'll get the text present in it.

Hasan Fahim
  • 3,875
  • 1
  • 30
  • 51
0

Use EventHandler Gridview_CellEdit or some similar to this. And then if (selecteditems.count>0) you can get a value of them. With creating a new variable, of course.

Viktorianec
  • 361
  • 6
  • 22
0

Set the Command Argument as

CommandArgument='<%# DataBinder.Eval(Container, "RowIndex") %>' CommandName = "QC"

And in the RowCommand Event

 if (e.CommandName == "QC")            
 {
     int RowIndex = Convert.ToInt32(e.CommandArgument);

Get the values u want based on the RowIndex.

thevan
  • 10,052
  • 53
  • 137
  • 202