get row index of row from datatable from primary key

How get row index of particular row from datatable 

for eg.

        i have create table of following column and fill rows in that and bind it into gridview

            now i want to get row index of selected row from column LedgerDetailID , how and reply me
 

            DataTable tbl = new DataTable();
            tbl.Columns.Add(new DataColumn("Index", System.Type.GetType("System.Int32")));
            tbl.Columns.Add(new DataColumn("LedgerDetailID", System.Type.GetType("System.Int32")));
            tbl.Columns.Add(new DataColumn("AcId", System.Type.GetType("System.Int32")));
            tbl.Columns.Add(new DataColumn("VouDate", System.Type.GetType("System.DateTime")));
            tbl.Columns.Add(new DataColumn("VouNo", System.Type.GetType("System.String")));
            tbl.Columns.Add(new DataColumn("ChallanNo", System.Type.GetType("System.String")));
            tbl.Columns.Add(new DataColumn("TransactionTypeId", System.Type.GetType("System.Int32")));
            tbl.Columns.Add(new DataColumn("TransactionName", System.Type.GetType("System.String")));
            tbl.Columns.Add(new DataColumn("Amount", System.Type.GetType("System.Double")));
            tbl.Columns.Add(new DataColumn("Adjust Amount", Type.GetType("System.Double")));
            tbl.Columns.Add(new DataColumn("Balance", Type.GetType("System.Double")));

0
bhaveshkrana
8/11/2008 1:04:59 PM
asp.net.object-datasource 16182 articles. 0 followers. Follow

7 Replies
860 Views

Similar Articles

[PageSpeed] 21

hi,

 

 How can you select a row from datatable.?

 

R u using gridview to display it and from the gridview slection you want to get the selected row.


Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue
:) Sibi :)
0
Sibin
8/11/2008 1:11:17 PM

 i m using gridview for display and select from gridview on rowcommand event

0
bhaveshkrana
8/11/2008 1:13:29 PM

 Hi,

In the row comand itself you can get the index

as

e.Row.RowIndex 


Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue
:) Sibi :)
0
Sibin
8/11/2008 1:18:44 PM

 i want index of table row not gridview row

0
bhaveshkrana
8/11/2008 1:20:43 PM

 Hello,

 

As datatable is bind to the gridview . the rowindex of gridview and table will be same


Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue
:) Sibi :)
0
Sibin
8/11/2008 1:22:24 PM

in datatable, fill row and using defaultview for filter row and view is bind with gridview,

    so row index is not same as grid view rowindex
 

0
bhaveshkrana
8/11/2008 1:26:49 PM

 Ah ok...

 

So are you binding the Index field of datatable to gridview?

Create a template field

Insert a hiddenfield hdnID

Assign hiddenfield value as Index

and in row command you can get the selected rowindex

and after that you can 

use

Dim hdn as new hiddenfield

hdn=CTYPE(e.row.FindControl("hdnID"),HiddenField)

hdn.Value  will give you the correct index ...

Give a try and we will see


Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue
:) Sibi :)
0
Sibin
8/11/2008 1:32:50 PM
Reply:

Similar Artilces:

Get row index of found row
How do I find the row index after searching a Dataset Table? For example, <code> Dim recId As String = Request.QueryString("r") Dim r As DataRow Dim tbl As DataTable = ds.Tables("drivers") tbl.PrimaryKey = New DataColumn() {tbl.Columns("recId")} If NOT IsNothing(tbl.Rows.Find(recId)) Then                r = tbl.Rows.Find(recId) End If </code> Next, I want to know the row index of the row, r, so the user can move foward and back, from this point, through the rows in the table, in order to display...

select row grid with arrow key (up&down) and get datakey this row whit enter key
hi friends how i can select row grid with arrow key (up&down) and get datakey this row whit enter key but that in client side code plzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz  help me thanks a lot     this article talks about how to bind keyboard shortcut to Click event of the botton http://www.vikramlakhotia.com/Binding_keyboard_shortcut_in_AspNet.aspx also this article discusses the same http://forums.asp.net/p/1119365/1748317.aspx#1748317Vikram www.vikramlakhotia.comPlease mark the answer if it helped you hi vik20000in  tanks a ...

How to get the row index of a selected row in listview control
Can someone please tell me how to get the index of a selected row in a listview.  <ItemTemplate> <asp:LinkButton runat="server" class="linkButton" id="xxxxx" Text='<%#Eval("documenttype") %>' CommandName="OpenFile" CommandArgument='<%#Eval("DocumentKey") %>'></asp:LinkButton></ItemTemplate>what you have to do is, in itemcommand event of ListView, you have to get the value of row indexif(e.CommandName == "corrospondingcommaandname"){     &nb...

how to select a row in datagrid and return primary key of that row?
any body? i am suck! =( pls help!! b General rule is to assign a primary column to DataKeysField attribute of the grid and then use GridItem.DataKeys(Index) to extract the valueBug [MCSD] so would that be under the SUB of GridItem_EditCommand? or Griditem_SelectedIndexChanged?? i just don't get it.. so stuck! =( b Does not matter. You can use that logic in any grid events as: dim intID=CInt(DataGrid1.DataKeys(e.Item.ItemIndex)) Bug [MCSD]...

To get the row index of selected row in grid view
Hi I have a grid view with a column of checkboxes. if I check a checkbox all the remaining checkboxes should be unchecked except the current one.protected void chkHeadCoach_CheckedChanged(object sender, EventArgs e) {foreach (GridViewRow rowitem in grdv.Rows) {CheckBox chkHeadCoach = (CheckBox)(rowitem.FindControl("chkHeadCoach"));if (chkHeadCoach.Checked) {if(rowitem.RowIndex != //row index of the row I checked now) {chkHeadCoach.Checked = false; } } } how can I get the row index of the row I checked now? }Thanks & Regards,Abhiram Reddy Mekha. AbhiramReddyMekh...

how can i get index of row in grid by clicking on grid row
how can i get index of row in grid by clicking on grid row Hi there,Under the selectedindexchanged event of the gridview put this:protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { int index= GridView1.SelectedIndex;//to get the indexGridViewRow row= GridView1.SelectedRow; //to get the selected row} thanks,Murthy Dont forget to click "Mark as Answer" on the post that helped you. This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped. Once you get the index of the row, how do ...

how to Insert a row in typed dataset datatable in the first row index
 Hi,When we use typed datasets. I have type DataTable: detialstable as detailsdataTableI want to add new detailsRow to detailstable. But I want the row to go to the beginning of the table and not the end.Can any one help pls?Thanks :) Thanks a lot, I appreciate your taking the time to help me.  Hi there,                 you have to use the InsertAt method of DataRowCollection here I put a simple code to see that.         DataSet1 ds = new DataSet1();     ...

how do I get the row index of the row that was just updated in the row_updated function?
How do I get the row index of the row that was just updated in the row_updated function?  Please don't tell me to use the row updating function because I tried to do what I want under row_updating but it doesn' t work for what I need to do.   Thanks. aspusername: Please don't tell me to use the row updating function Sorry, but that's where the information is: int LastRowUpdated; protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { LastRowUpdated = e.RowIndex; } protected void GridView1_RowUpdated...

Get value for each row in a DataTable object
I am really stacked on this one even though it seems to be so simple. I am not able to get the value of each row and store it array list all  I am getting is objects which I am not able to covert to array of strings. Anybody who can help me with this bummer? thank you      public static ArrayList GetExchangeGateways(DataTable tbl)    {        ArrayList list = new ArrayList();        foreach (DataRow r in tbl.Rows)        {  ...

how to compare rows in the datatable and remove the duplicate rows (before removal of duplicate row i need to append those values to original rows)
Hii.             I have a datatable in that i have some rows.. i need to compare those rows one among the other based on first column only. If its duplicate row i need to append those col values to original row. For example here is the data in the table.: Total - 13 columns Name:     Jan:   Feb:   March:...............................Dec  Phani      2        4          ...

Getting the index of a row in a GridView by key value
Hi,I got the SelectedDataKey's Value property from the GridView. Say an row in the grid represents an item, the value mentioned is the item code(unique). I've updated the corresponding row in the DB so now after the Databind() it appears in a different index in the grid.How do I find the new index of that item, so that I can set the GridView.SelectedIndex property to the new index and visually stay "on" the same item?Thanks.  Eldar  Got it, 1 //item_code - int, is the one that interests me to find and select in the grid.2 3 int current_index = 0;4 ...

getting the primary key of the newly inserted row
i have a nested gridview that inserts in record in two table (ORIGINALESTIMATE(CostingID PK), ESTIMATE DETAILS(Details PK, CostingID FK) now my problem is that it succesfully inserts record to originalestimate table and it stops there. it does not go to the second insert statement and does not get the value of the primary of the newly inserted row.. can please look at my code below and tell me how can i do this... protected void BtnSave_Click(object sender, EventArgs e) { SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DBSystemConnection...

How to delete row from GridView control
Hello,  I am working on an ASP.NET 2.0 app, and I am trying to wire up a "Delete" button to a gridview control on a form. Here is the code for the ASP :  <asp:GridView ID="gvInConditions" runat="server" AutoGenerateColumns="true" OnRowDeleting="gvInConditions_RowDeleting" DataKeyNames="Condition_ID" >         <Columns>                <asp:CommandField ButtonType="Button" SelectText=&...

How to get record count or row count of rows in reporting service table object?
SSRS 2005.  Let's say I define ONE dataset.  In the page layout I drop in 2 tables.  table1 and table2.  In each of these 2 tables, I add a filter. Let's call the field Active Flag, and I filter on "Y" and "No" respectively.  Now, at the bottom of the report(and not inside the tables themselves) I want to drop 2 textboxes onto the page layout.  I want to get the record count from table1, and the record count in table 2, and place it in each textbox at the bottom of the page that shows the total records per table.  Sounds easy, bu...

Web resources about - get row index of row from datatable from primary key - asp.net.object-datasource

Stack Overflow
Stack Exchange log in - careers - chat - meta - about - faq Questions Tags Users Badges Unanswered Ask Question Top Questions interesting 325 ...

University of Southampton - Wikipedia, the free encyclopedia
The University of Southampton is a British Russell Group university located in the city of Southampton , United Kingdom . The origins of the ...

London Metropolitan University - Wikipedia, the free encyclopedia
London Metropolitan University (London Met), located in London , England , was formed on 1 August 2002 by the amalgamation of the University ...

Google Chart Tools — Google Developers
This page has moved to Google Developers. Welcome! Learn more Dismiss Home Products Events Showcase Google Chart Tools Overview Hello Charts! ...

Google Chart Tools — Google Developers
Powerful, simple to use, and free.

AribaWeb (aribaweb.org) - Google Groups
Search Images Maps Play YouTube News Gmail Documents More Calendar Translate Mobile Books Offers Wallet Shopping Blogger Reader Finance Photos ...

Linux Syscall Reference
Generated from Linux kernel 2.6.35.4 using Exuberant Ctags , Python , and DataTables . Developed and maintained by Greg Ose .

NewsMap
... over one weekend where the author had a bit of extra time on his hands. Built with the help of the following tools: Bootstrap jVectorMap DataTables ...

A Map for the Microsoft Application Development Platform
... Localization N-Tier Remote Data Security Silverlight SQL Azure SQL Server Streaming XML Features ADO.NET DataSet ADO.NET DataTable ...

Application Development Framework
Articles: Application Development Framework

Resources last updated: 1/18/2016 6:20:07 AM