473,473 Members | 1,847 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Need GridView Help

I'm displaying data in a GridView that allows user to select a row. When a
button is clicked, I need to locate the selected row.

The problem is that I need an ID value from the selected row, but I do not
want to display that ID value in the grid. I tried creating a hidden column,
but I can't seem to be able to access it when the button is clicked. (At
least, hidden columns do not appear to show up in the Cells collection of
the selected row.)

Is there any way to get an ID for the selected row without displaying that
ID to the user?

Also, does anyone know if there's any way to populate a GridView control
without using the DataSource property, by just programatically adding rows
to the grid?

Thanks.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

Jan 24 '08 #1
4 1055
"Jonathan Wood" <jw***@softcircuits.comwrote in message
news:eX**************@TK2MSFTNGP05.phx.gbl...
Is there any way to get an ID for the selected row without displaying that
ID to the user?
When the data is bound to the GridView, populate the button's
CommandArgument property with the ID...

However, there's no need to use a button if all you want is the user to be
able to select a row:

protected void MyGridView_RowDataBound(object sender, GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Style["cursor"] = "pointer";
e.Row.Attributes.Add("onclick",
ClientScript.GetPostBackEventReference(MyGridView, "Select$" +
e.Row.RowIndex.ToString()));
}
}

protected void MyGridView_SelectedIndexChanged(object sender, EventArgs e)
{
Response.Redirect("OtherPage.aspx?ID=" +
MyGridView.SelectedValue.ToString(), false);
}
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jan 24 '08 #2
Mark,
When the data is bound to the GridView, populate the button's
CommandArgument property with the ID...

However, there's no need to use a button if all you want is the user to be
able to select a row:

protected void MyGridView_RowDataBound(object sender, GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Style["cursor"] = "pointer";
e.Row.Attributes.Add("onclick",
ClientScript.GetPostBackEventReference(MyGridView, "Select$" +
e.Row.RowIndex.ToString()));
}
}

protected void MyGridView_SelectedIndexChanged(object sender, EventArgs e)
{
Response.Redirect("OtherPage.aspx?ID=" +
MyGridView.SelectedValue.ToString(), false);
}
Yeah, I'll play around with that. But, like I mentioned elsewhere in this
thread, I don't do any processing when the item is selected. I need to be
able to access the ID of the selected row when a button outside the grid is
pressed. It sounds like this is mostly geared towards handling row
events--unless there's a bit more to this.

Thanks.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

Jan 24 '08 #3
"Jonathan Wood" <jw***@softcircuits.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Yeah, I'll play around with that. But, like I mentioned elsewhere in this
thread, I don't do any processing when the item is selected. I need to be
able to access the ID of the selected row when a button outside the grid
is pressed.
In that case, the CommandArgument property is definitely the way to go...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jan 24 '08 #4
I'll have to take your word for it. I can't seem to see how CommandArgument
could be made to work for my purposes.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
"Jonathan Wood" <jw***@softcircuits.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>Yeah, I'll play around with that. But, like I mentioned elsewhere in this
thread, I don't do any processing when the item is selected. I need to be
able to access the ID of the selected row when a button outside the grid
is pressed.

In that case, the CommandArgument property is definitely the way to go...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Jan 24 '08 #5

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

Similar topics

5
by: Dick | last post by:
I have a GridView bound to an ObjectDataSource. I have a Button that calls GridView.DataBind. I want the row that is selected before the DataBind to still be selected afterwards. This happens...
1
by: Miguel Dias Moura | last post by:
Hello, I have a GridView in my page which is created in runtime. It works fine. My page has 2 Asp Buttons: - The HIDE button makes GridView.Visible = False; - The SHOW button makes...
1
by: Siva | last post by:
Hi, I have a 3 tier ASP.Net app for a handheld which needs to fetch orders from database via a DAL and populate it in a gridview using objectdatasource. In the search page I have a few parameters...
5
by: Siva | last post by:
Hello I have a dropdownlist inside the gridview as a template column defined as follows: <asp:TemplateField HeaderText="Choose Location"> <ItemTemplate> <asp:DropDownList ID="ddlChooseLoc"...
3
by: mosscliffe | last post by:
I have a gridview and in the GridView1_SelectedIndexChanged routine I am attempting to get at the data in the row I have done it successfully with cells 'Access the contents of a field in a...
8
by: pamelafluente | last post by:
I am beginning aspNet, I know well win apps. Need a simple and schematic code example to start work. This is what I need to accomplish: ---------------------- Given button and a TextBox on a...
0
by: yeltsin27 | last post by:
I need some advice on handling dynamically added controls in a GridView. My app takes an uploaded CSV file containing addresses, converts it to a DataTable, databinds the DataTable to a...
0
by: LiamLiamLiam | last post by:
G'day all. I having a problem with my formview. I'll ty to explain my situation as best as i can. I have a page with a search field at the top which is just a simple asp:textbox. Below that i...
4
by: svgeorge | last post by:
I NEED TO COLLECT FROM THE GRIDVIEW(DATASELECTED) IN TO A TABLE(SelectedPayment) -------------------------------------------------------------------------------- How TO COLLECT THE ROWS...
0
by: steve | last post by:
I have been fighting with trying to update a GridView for a while. I don't want to use the "built-in" way to do it because I am using business layer methods for updating and deleteing and I don't...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.