By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,238 Members | 1,771 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,238 IT Pros & Developers. It's quick & easy.

DataView / DataRow

P: n/a
'ello

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

Thanx
Hein
Nov 15 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
'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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.