DataGrid_ItemCommand

  • Thread starter Thread starter mg
  • Start date Start date
M

mg

I have a DataGrid with 2 Button Columns of type LinkButton
in a WebForm.

The DataGrid is populated:

private void Page_Load(object sender, System.EventArgs e)
{
if (! IsPostBack)
{
DataAdapter1.Fill(dataSet11);
Page.DataBind();
}
}


I'm able to detect which column was selected by clicking
on one column and seeing "LEFT" displayed or the other
column and seeing "RIGHT" displayed in a Label. But, I'm
not able to get the data in an individual cell. That
is, "e.Item.Cells[0].Text" brings back nothing. [Clues?
e.Item.Cells.ToString()
returns "System.Web.UI.WebControls.TableCellCollection"
and e.Item.Cells[0].ToString()
returns "System.Web.UI.WebControls.TableCell"]

private void DataGrid1_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if (e.CommandName == "Select1")
Label1.Text = e.Item.Cells[0].Text; // returns nothing
//Label1.Text = "LEFT";
}
else
{ {
Label1.Text = e.Item.Cells[1].Text; // returns nothing
//Label1.Text = "RIGHT";
}
}

How can I see the data contents of an individual cell of
the DataGrid?
 
instead of e.Item.Cells[0].Text, which is only really valid for bound
columns, you need to get the button text...

try:
Dim linkbtnCRID As LinkButton = e.Item.Cells(2).Controls(0)
Dim szCRID = linkbtnCRID.Text


good luck.
 
obviously in the example text given you need to change your cells(2) to
cells(X) where X is the column number...

Daniel Bass said:
instead of e.Item.Cells[0].Text, which is only really valid for bound
columns, you need to get the button text...

try:
Dim linkbtnCRID As LinkButton = e.Item.Cells(2).Controls(0)
Dim szCRID = linkbtnCRID.Text


good luck.

mg said:
I have a DataGrid with 2 Button Columns of type LinkButton
in a WebForm.

The DataGrid is populated:

private void Page_Load(object sender, System.EventArgs e)
{
if (! IsPostBack)
{
DataAdapter1.Fill(dataSet11);
Page.DataBind();
}
}


I'm able to detect which column was selected by clicking
on one column and seeing "LEFT" displayed or the other
column and seeing "RIGHT" displayed in a Label. But, I'm
not able to get the data in an individual cell. That
is, "e.Item.Cells[0].Text" brings back nothing. [Clues?
e.Item.Cells.ToString()
returns "System.Web.UI.WebControls.TableCellCollection"
and e.Item.Cells[0].ToString()
returns "System.Web.UI.WebControls.TableCell"]

private void DataGrid1_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if (e.CommandName == "Select1")
Label1.Text = e.Item.Cells[0].Text; // returns nothing
//Label1.Text = "LEFT";
}
else
{ {
Label1.Text = e.Item.Cells[1].Text; // returns nothing
//Label1.Text = "RIGHT";
}
}

How can I see the data contents of an individual cell of
the DataGrid?
 
Thanks!
-----Original Message-----
obviously in the example text given you need to change your cells(2) to
cells(X) where X is the column number...

instead of e.Item.Cells[0].Text, which is only really valid for bound
columns, you need to get the button text...

try:
Dim linkbtnCRID As LinkButton = e.Item.Cells(2).Controls (0)
Dim szCRID = linkbtnCRID.Text


good luck.

mg said:
I have a DataGrid with 2 Button Columns of type LinkButton
in a WebForm.

The DataGrid is populated:

private void Page_Load(object sender, System.EventArgs e)
{
if (! IsPostBack)
{
DataAdapter1.Fill(dataSet11);
Page.DataBind();
}
}


I'm able to detect which column was selected by clicking
on one column and seeing "LEFT" displayed or the other
column and seeing "RIGHT" displayed in a Label. But, I'm
not able to get the data in an individual cell. That
is, "e.Item.Cells[0].Text" brings back nothing. [Clues?
e.Item.Cells.ToString()
returns "System.Web.UI.WebControls.TableCellCollection"
and e.Item.Cells[0].ToString()
returns "System.Web.UI.WebControls.TableCell"]

private void DataGrid1_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if (e.CommandName == "Select1")
Label1.Text = e.Item.Cells[0].Text; // returns nothing
//Label1.Text = "LEFT";
}
else
{ {
Label1.Text = e.Item.Cells[1].Text; // returns nothing
//Label1.Text = "RIGHT";
}
}

How can I see the data contents of an individual cell of
the DataGrid?


.
 
Back
Top