473,466 Members | 1,368 Online
Bytes | Software Development & Data Engineering Community
Create 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 13127
Hein,

DataRow dr =
((DataRowView)BindingContext[MyDataGrid.DataSource].Current).Row;

---
Steven Wood

"Hein Albrecht" <he***@magnumsimplex.com> wrote in message
news:%2****************@TK2MSFTNGP11.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 =
(CurrencyManager)theForm.BindingContext[theGrid.DataSource,
theGrid.DataMember];

next, obtain the data view:

DataView theView = (DataView)cm.List;

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***@magnumsimplex.com> wrote in message
news:%2****************@TK2MSFTNGP11.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.BindingContext.

Any other suggestions?

Thanx

Hein

"Steven Wood" <st*********@hotmail.com> wrote in message
news:u0**************@TK2MSFTNGP10.phx.gbl...
Hein,

DataRow dr =
((DataRowView)BindingContext[MyDataGrid.DataSource].Current).Row;

---
Steven Wood

"Hein Albrecht" <he***@magnumsimplex.com> wrote in message
news:%2****************@TK2MSFTNGP11.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.BindingContext.


I can think of two possible ways.

First, a DataGrid:

<ASP:DATAGRID id="myDataGrid" runat="server"
onitemcommand="myDataGrid_ItemCommand">
<COLUMNS>
<ASP:BUTTONCOLUMN HeaderText="Select Row"
ButtontType="PushButton"
Text="Select"
CommandName="SelectRow">
</ASP:BUTTONCOLUMN>
<ASP:BOUNDCOLUMN HeaderText="MyID" 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_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
TableCell myID = e.Item.Cells[1];
string key = myID.Text;
DataRow[] dr =
((DataSet)Session["MyDataSet"]).Tables[0].Select("MyID=" + key);
}

or

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

protected void myDataGrid_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
TableCell myID = e.Item.Cells[1];

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

if(((Button)e.CommandSource).CommandName == "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
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...
5
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...
1
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...
8
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 =...
36
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...
11
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...
5
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...
1
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...
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
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
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
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: 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...
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 ...

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.