473,387 Members | 1,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

DataGrid_ItemCommand

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?
Nov 17 '05 #1
3 4411
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:09****************************@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?

Nov 17 '05 #2
obviously in the example text given you need to change your cells(2) to
cells(X) where X is the column number...

"Daniel Bass" <da**************@MAILpostmaster.co.uk> wrote in message
news:%2****************@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:09****************************@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?


Nov 17 '05 #3
mg
Thanks!
-----Original Message-----
obviously in the example text given you need to change your cells(2) tocells(X) where X is the column number...

"Daniel Bass" <da**************@MAILpostmaster.co.uk> wrote in messagenews:%2****************@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:09****************************@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?


.

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: alexB | last post by:
You can call the sub() just like any other sub() or function() like so... Call DataGrid1_SelectedIndexChanged(sender,e ) Depending on the circumstances "sender" and "e" may be irrelevent, in...
0
by: Divya Chawla | last post by:
I have a master detail datagrid capable of expanding and collapsing when u click on an imagebutton. I also have used the Sort event handler for the child columns. However, when I click on a...
3
by: amber | last post by:
Hello, I have a datagrid with about 5 columns. It's datasource is a dataset that also contains a 'comments' field, but I'm not displaying it, as it would take up too much space. What I would like...
0
by: SteveC | last post by:
In my ASP.NEt codebehind, I declare a public var for a DataGrid. Then in the TextChanged event handler for a TextBox, I create a <div> tag, stuff it inside the form, then instance a DataGrid and...
3
by: Stuart | last post by:
Hi there I am using a button column>SELECT and a datagrid.Item_Command to take a value from the datagrid (in this case a customer account number) - store that value in to a session variable and...
2
by: Tim_Mac | last post by:
hi, i have an aspx page which dynamically loads a user control and adds it to a placeholder. the control is recreated and added to the placeholder for postbacks as well. the user control...
4
by: Jonathan Upright | last post by:
Greetings to anyone who can help: I'm using WebMatrix to make ASP.NET pages, and I chose the "Editable DataGrid" at the project selector screen. As you may know, it defaults to the Microsoft...
19
by: Joe | last post by:
I have an aspx page (referred to here as page_1) with a datagrid whose first column contains hyperlinks. When a user clicks one of these hyperlinks, he will navigate to another aspx page (referred...
3
by: narpet | last post by:
Hello all... Using C# I am getting data for a form from a sql database table. I am able to get the data correctly (with appropriate dataset and table adapter), but I can't figure out how to add...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.