473,778 Members | 1,934 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataView / DataRow

'ello

How can I get the DataRow of the DataGrid's SelectedItem for the bound
DataView's DataTable?

Thanx
Hein
Nov 15 '05 #1
4 13154
Hein,

DataRow dr =
((DataRowView)B indingContext[MyDataGrid.Data Source].Current).Row;

---
Steven Wood

"Hein Albrecht" <he***@magnumsi mplex.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
'ello

How can I get the DataRow of the DataGrid's SelectedItem for the bound
DataView's DataTable?

Thanx
Hein

Nov 15 '05 #2
Hello,

First, obtain the corresponding CurrencyManager instance like this:

CurrencyManager cm =
(CurrencyManage r)theForm.Bindi ngContext[theGrid.DataSou rce,
theGrid.DataMem ber];

next, obtain the data view:

DataView theView = (DataView)cm.Li st;

and finally, get the row:

DataRow row = theView[cm.Current].Row;

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Hein Albrecht" <he***@magnumsi mplex.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
'ello

How can I get the DataRow of the DataGrid's SelectedItem for the bound
DataView's DataTable?

Thanx
Hein


Nov 15 '05 #3
'ello

Thanx for the replies, but I seemed to forget to mention one thing. My

application uses C# webforms, so I can't use
System.Windows. Forms.BindingCo ntext.

Any other suggestions?

Thanx

Hein

"Steven Wood" <st*********@ho tmail.com> wrote in message
news:u0******** ******@TK2MSFTN GP10.phx.gbl...
Hein,

DataRow dr =
((DataRowView)B indingContext[MyDataGrid.Data Source].Current).Row;

---
Steven Wood

"Hein Albrecht" <he***@magnumsi mplex.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
'ello

How can I get the DataRow of the DataGrid's SelectedItem for the bound
DataView's DataTable?

Thanx
Hein


Nov 15 '05 #4
Hein,
Thanx for the replies, but I seemed to forget to mention one thing. My
application uses C# webforms, so I can't use
System.Windows. Forms.BindingCo ntext.


I can think of two possible ways.

First, a DataGrid:

<ASP:DATAGRID id="myDataGrid " runat="server"
onitemcommand=" myDataGrid_Item Command">
<COLUMNS>
<ASP:BUTTONCOLU MN HeaderText="Sel ect Row"
ButtontType="Pu shButton"
Text="Select"
CommandName="Se lectRow">
</ASP:BUTTONCOLUM N>
<ASP:BOUNDCOLUM N HeaderText="MyI D" datafield="MyID ">
</ASP:BOUNDCOLUMN >
</COLUMNS>
</ASP:DATAGRID>

Then in your code behind file either:

1. Store the DataSet for the Grid in Session State (depending on its size)
and:

protected void myDataGrid_Item Command(object source,
System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
{
TableCell myID = e.Item.Cells[1];
string key = myID.Text;
DataRow[] dr =
((DataSet)Sessi on["MyDataSet"]).Tables[0].Select("MyID=" + key);
}

or

(2) go back to the database with the id and get the single record:

protected void myDataGrid_Item Command(object source,
System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
{
TableCell myID = e.Item.Cells[1];

int id = int.Parse(myID. Text);

if(((Button)e.C ommandSource).C ommandName == "SelectRow" )
{
DataRow dr = // fetch the record from the database using the id
}
}

---
Steven Wood

Nov 15 '05 #5

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

Similar topics

9
2100
by: Raymond Lewallen | last post by:
I have a dataview in which the sort property will not sort the dataview. Here's is a simple scenario similar to what I am doing: Class Foo Private Function Retrieve() As DataView ' Returns a DataView with 2 columns and 3 rows Dim ADOHelper As New DAL.ADOHelper Return ADOHelper.GetMyDataview() End
5
1934
by: Richard | last post by:
Windows Forms, csharp, 20 rows in DataTable 14 shown in view after filter applied. For any of the 14 how do I do the datarow or something else thing to access the data in the row of the table behind the view selected on the datagrid. DataGrid only gives an index based on the 1-14 visible on the datagrid and I can't seem to update anything I see in the dataview quickwatch that I can update the underlying row. I could manually keep track...
1
2575
by: Johann Blake | last post by:
I'm not sure that I entirely understand the purpose of the AcceptChanges methon in a DataView. I added a new record to a DataView and noticed that its RowState indicated it as being "Added". If I execute the Update method on an adapter for the table that the DataView is based on, the new record will indeed be written to the database. But if I call AcceptChanges prior to executing the Update method, the RowState for the new record is...
8
3900
by: Dave Hagerich | last post by:
I'm using a DataGrid with a DataSet and I'm trying to filter the data being displayed, using the following code as a test: DataView theView = new DataView(theDataSet.Tables); theView.RowFilter = "'Record ID' = '0'"; theView.RowStateFilter = DataViewRowState.ModifiedCurrent; Debug.WriteLine(string.Format("RowFilter = {0}", theView.RowFilter)); RecordDataGrid.DataSource = theView; RecordDataGrid.DataBind();
36
4483
by: kjvt | last post by:
Based on a prior posting, I've written a function to convert a recordset to a dataview. The first call to the function for a given recordset works perfectly, but the second call always returns a dataview with a count = 0. Can someone explain why and how I might work around this problem? Here is the code for my function: Public Shared Function GetViewFromRS(ByVal pRS As ADODB.Recordset) _ As DataView
11
27437
by: Tim Frawley | last post by:
I need to return a DataRow or the Row Index in a DataSet wherein the value I am attempting to find is not a primary key. I have to do this often, more than 200 times when importing a file so it needs to be fast. Could I use a Dataview to filter for the value (which is unique) and return either the DataRow object so I can modify it and put it back into the DataSet the view is based on or somehow get the RowIndex in the DataSet that the...
5
8834
by: David Wender | last post by:
I want to create a dataview with a sort on multiple columns. However, when I use FindRows, I only want to search some of the columns, not all. Is this possible? I have not been able to make it happen. Dim objKeys(2) as Object objKeys(0) = "CL" objKeys(2) = 4000 Dim posView As DataView = New DataView(posDS.Tables("Positions"), _
1
2978
by: =?Utf-8?B?UmljaA==?= | last post by:
Hello, I set a dataview to a table. Then I bind a currencyManager to the dataview. I can iterate through the dataview no problem so far. Then I sort the dataview on a certain field and rebind the currencyManager to the dataview. I can still iterate through the newly sorted dataview OK. The problem is that the row order of the underlying table did not change with the sort. Now the rows are out of order if I want to set a datarow...
0
9629
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9465
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10296
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8954
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7474
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4031
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 we have to send another system
3
2863
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.