?
Solved

selecting the underlying data row from ItemCommand

Posted on 2003-03-14
5
Medium Priority
?
426 Views
Last Modified: 2012-06-27
Is it possible to access the underlying datarow from a datagrid through the ItemCommand event handler.
I tried something like :

private void OnItemCommand(object sender, DataGridCommandEventArgs e)
{
DataRowView myRow = (DataRowView) e.Item.DataItem;
.....
}

and have also tried using DataRow myRow = (DataRow) e.Item.DataItem;

but the datarow never gets instantiated.

Many Thanks,

Olja
0
Comment
Question by:olja
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 6

Expert Comment

by:thomasdodds
ID: 8139464
you've got to use the datagrid's datakeys functionality... make sure you have set a ket for for the data grid and the same column as key in your dataset ... then

string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();

dsDataSet.dtDataTableRow r;
r = dsDataSet.TableName.FindByTableColumn(key);


now you have the specific row in the dataset that corresponds to the row in the datagrid...
0
 
LVL 6

Accepted Solution

by:
thomasdodds earned 150 total points
ID: 8139490
where:

DataGrid1 = your datagrid
dsDataSet = your dataset
dtDataTableRow  = your dataset data table row
TableName = your dataset data table name
FindByTableColumn = FindBy + the column you set as key

ALL should show in the intellisense of your MS IDE if you are using a typed dataset...
0
 
LVL 6

Expert Comment

by:thomasdodds
ID: 8168851
why the B grade?
0
 
LVL 1

Author Comment

by:olja
ID: 8171403
Thomas,
your answer didn't describe how to set the dataset keys and i didn't end up using your solution. Having said all that, i really appreciate your help and if i had known this meant something to you i would have given you an A.

Thanks,
Olja
0
 
LVL 6

Expert Comment

by:thomasdodds
ID: 8174462
then you need to review the grading guidelines for this site ... I would have showed you how to do it if you had asked ... you never gave me the chance ... I recommend doing the walkthrough examples provided in the Documentation supplied with VS.NET ... will give you a good comfort level in using the various features of the server controls
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question