473,385 Members | 1,838 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,385 software developers and data experts.

How to get a particular selected row ID from a grid view .

Hi groups,

How to get a particular selected row ID from a grid view control where i have placed imagebutton.
On click event how i can get the ROW ID ?

--
Mähésh Kumär. R

Nov 17 '05 #1
4 3207
Yeah it's not real obvious. I think you can get what you want from
this:

DataRowView rv = (DataRowView)dg.SelectedRows[0].DataBoundItem;

DataRow row = rv.Row;

//Use row like normal.

Nov 17 '05 #2
Hi,

It depends of how you created the grid, did you bind the rowID to any column or control?
how you declared your grid?

you could do like this ( CtpRecord is a business class and I'm binding the grid to a collection ) :

<asp:templatecolumn ItemStyle-VerticalAlign="Top" ItemStyle-Width="100" ItemStyle-HorizontalAlign="left" >
<itemtemplate>
<asp:LinkButton Runat=server CommandName="edit" CommandArgument='<%# ((CtpRecord)Container.DataItem).ID.ToString()%>' >
<span ><%# ((CtpRecord)Container.DataItem).LogNumber%></span>
</asp:LinkButton>

</itemtemplate>
</asp:templatecolumn>
Then in the code behind:
protected void RecordEditCommand(object sender, DataGridCommandEventArgs e)
{
int ID = Convert.ToInt32( e.CommandArgument ) );

}
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Maheshkumar.R" <cy**********@yahoo.com> wrote in message news:ez**************@TK2MSFTNGP09.phx.gbl...
Hi groups,

How to get a particular selected row ID from a grid view control where i have placed imagebutton.
On click event how i can get the ROW ID ?

--
Mähésh Kumär. R

Nov 17 '05 #3
Thanks a lot Machin..
Mahes
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote in message news:e4**************@TK2MSFTNGP09.phx.gbl...
Hi,

It depends of how you created the grid, did you bind the rowID to any column or control?
how you declared your grid?

you could do like this ( CtpRecord is a business class and I'm binding the grid to a collection ) :

<asp:templatecolumn ItemStyle-VerticalAlign="Top" ItemStyle-Width="100" ItemStyle-HorizontalAlign="left" >
<itemtemplate>
<asp:LinkButton Runat=server CommandName="edit" CommandArgument='<%# ((CtpRecord)Container.DataItem).ID.ToString()%>' >
<span ><%# ((CtpRecord)Container.DataItem).LogNumber%></span>
</asp:LinkButton>

</itemtemplate>
</asp:templatecolumn>
Then in the code behind:
protected void RecordEditCommand(object sender, DataGridCommandEventArgs e)
{
int ID = Convert.ToInt32( e.CommandArgument ) );

}
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Maheshkumar.R" <cy**********@yahoo.com> wrote in message news:ez**************@TK2MSFTNGP09.phx.gbl...
Hi groups,

How to get a particular selected row ID from a grid view control where i have placed imagebutton.
On click event how i can get the ROW ID ?

--
Mähésh Kumär. R

Nov 17 '05 #4
Hi,
Did it work?

After reading the other reply I was unsure if it was a web grid or a win one.

Also r u using C# 2.0 ?

The code I sent was done under 1.1 but it should work the same under 2.0

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Maheshkumar.R" <cy**********@yahoo.com> wrote in message news:eN**************@tk2msftngp13.phx.gbl...
Thanks a lot Machin..
Mahes
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote in message news:e4**************@TK2MSFTNGP09.phx.gbl...
Hi,

It depends of how you created the grid, did you bind the rowID to any column or control?
how you declared your grid?

you could do like this ( CtpRecord is a business class and I'm binding the grid to a collection ) :

<asp:templatecolumn ItemStyle-VerticalAlign="Top" ItemStyle-Width="100" ItemStyle-HorizontalAlign="left" >
<itemtemplate>
<asp:LinkButton Runat=server CommandName="edit" CommandArgument='<%# ((CtpRecord)Container.DataItem).ID.ToString()%>' >
<span ><%# ((CtpRecord)Container.DataItem).LogNumber%></span>
</asp:LinkButton>

</itemtemplate>
</asp:templatecolumn>
Then in the code behind:
protected void RecordEditCommand(object sender, DataGridCommandEventArgs e)
{
int ID = Convert.ToInt32( e.CommandArgument ) );

}
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Maheshkumar.R" <cy**********@yahoo.com> wrote in message news:ez**************@TK2MSFTNGP09.phx.gbl...
Hi groups,

How to get a particular selected row ID from a grid view control where i have placed imagebutton.
On click event how i can get the ROW ID ?

--
Mähésh Kumär. R

Nov 17 '05 #5

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

Similar topics

4
by: Steve | last post by:
Visual Studio 2003 .Net / C# I have a datagrid, which is bound to a dataset at runtime when my page loads. When the user double clicks a row, I need to find out which row they have selected so...
2
by: X-Killer | last post by:
I've played around the datagrid control for some time and can't find any "rows" or "columns" property within it. What is the easiest way to find out the content of each fields of a selected row in...
1
by: Maheshkumar.R | last post by:
Hi groups, How to get a particular selected row ID from a grid view control where i have placed imagebutton. On click event how i can get the ROW ID ? thankz --
3
by: Brian Tkatch | last post by:
I have a form with two DataGrids, which are kept in sync manually via Stored PROCEDURE calls. That is, when a record is selected on the first grid, a stored PROCEDURE is CALLed to Fill() the next...
1
by: Dinu | last post by:
hi i am having a gridview in aspx page and a usercontrol in master page of that page now what i want is selected row text to be displayed in usercontrol i wrote code as follows: ...
2
by: Mike | last post by:
On my web form I have a gridview and I allow the user to edit a row but clicking a button above the grid. The Edit button takes them to a edit page with the details of the selected row. When they...
7
by: surikumarvinod | last post by:
hello, I have a page in wich i have 3 dropdowns and a grid view. when i click on the edit button in grid view to update a record it takes me to edit page. what i want is when i come back from...
1
by: imbirek8 | last post by:
Hi, I use GridView control in asp.net. I would like to write an event on the client site. When somebody click on row, I would like to clear all selected rows in GridView and changed cliked row...
0
by: cadab | last post by:
I have a data grid view, i have specified several columns through the designer that i would like to show on the grid, i have mapped them to the datasource, this works fine, the problem is, my data...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...

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.