Ask a Question related to ASP.NET General, Design and Development.
-
mg #1
DataGrid_ItemCommand
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?
mg Guest
-
Daniel Bass #2
Re: DataGrid_ItemCommand
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" <mg@theworld.com> wrote in message
news:09be01c3529b$25710c00$a301280a@phx.gbl...> 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?
Daniel Bass Guest
-
Daniel Bass #3
Re: DataGrid_ItemCommand
obviously in the example text given you need to change your cells(2) to
cells(X) where X is the column number...
"Daniel Bass" <danielbassNOJUNK@MAILpostmaster.co.uk> wrote in message
news:%23BSYMypUDHA.1832@TK2MSFTNGP09.phx.gbl...> 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" <mg@theworld.com> wrote in message
> news:09be01c3529b$25710c00$a301280a@phx.gbl...>> > 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?
>
Daniel Bass Guest
-
mg #4
Re: DataGrid_ItemCommand
Thanks!
your cells(2) to>-----Original Message-----
>obviously in the example text given you need to changewrote in message>cells(X) where X is the column number...
>
>"Daniel Bass" <danielbassNOJUNK@MAILpostmaster.co.uk>valid for bound>news:%23BSYMypUDHA.1832@TK2MSFTNGP09.phx.gbl...>> instead of e.Item.Cells[0].Text, which is only really(0)>> columns, you need to get the button text...
>>
>> try:
>> Dim linkbtnCRID As LinkButton = e.Item.Cells(2).ControlsLinkButton>> Dim szCRID = linkbtnCRID.Text
>>
>>
>> good luck.
>>
>> "mg" <mg@theworld.com> wrote in message
>> news:09be01c3529b$25710c00$a301280a@phx.gbl...>> > I have a DataGrid with 2 Button Columns of typeSystem.EventArgs e)>> > in a WebForm.
>> >
>> > The DataGrid is populated:
>> >
>> > private void Page_Load(object sender,clicking>> > {
>> > if (! IsPostBack)
>> > {
>> > DataAdapter1.Fill(dataSet11);
>> > Page.DataBind();
>> > }
>> > }
>> >
>> >
>> > I'm able to detect which column was selected byI'm>> > on one column and seeing "LEFT" displayed or the other
>> > column and seeing "RIGHT" displayed in a Label. But,[Clues?>> > not able to get the data in an individual cell. That
>> > is, "e.Item.Cells[0].Text" brings back nothing.returns "System.Web.UI.WebControls.TableCellCollection ">> > e.Item.Cells.ToString()
>> >nothing>> > 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; // returnsnothing>> > //Label1.Text = "LEFT";
>> > }
>> > else
>> > { {
>> > Label1.Text = e.Item.Cells[1].Text; // returnsof>> > //Label1.Text = "RIGHT";
>> > }
>> > }
>> >
>> > How can I see the data contents of an individual cell>>>>> > the DataGrid?
>>
>
>.
>mg Guest



Reply With Quote

