473,940 Members | 8,900 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

accessing selected row in dataset

Hi,
I wont to get the current row values from a dataset, any one know how to
reach those data ??
At the moment I use a work around, but it's not good ..
foreach (DataRow row in this.pitagorala voriDataSet.Add etti.Rows)
{

if (Convert.ToStri ng(row["Nome"])== sNomeU){
idutente = Convert.ToInt32 (row["id"]);
}
Because I don't want to show a label with the name ( sNomeU is =
label1.tetx )

Thanks to all.
Paolol
Jul 25 '06 #1
2 15383
paolol,

I assume you mean the currently selected row in a grid? If this is the
case, then what you want to do is get the binding context for the control,
and then pass the data set into it, like so:

// Get the context.
BindingContext context = dataGrid.Bindin gContext;

// Get the currency manager.
BindingManagerB ase manager = context[dataSet, memberName];

// Get the current row view.
DataRowView rowView = (DataRowView) manager.Current ;

// Get the row.
DataRow row = rowView.Row;

A few things to point out. The first parameter of the call to the
indexer for BindingContext needs to be the DataSource and the DataMember of
the data source. For example, if you bound the grid to the DataTable
directly, then just use that. If you bound to the DataSet and specified the
table name as the DataMember, then pass the data set and the member name.

You can also access the values in the row using the DataRowView.

Finally, you might just want to bind the text of the label to the
datasource directly. This is easier than setting it yourself when the
current selection changes.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"paolol" <paolol@no_spam salsan.netwrote in message
news:er******** *****@TK2MSFTNG P04.phx.gbl...
Hi,
I wont to get the current row values from a dataset, any one know how to
reach those data ??
At the moment I use a work around, but it's not good ..
foreach (DataRow row in this.pitagorala voriDataSet.Add etti.Rows)
{

if (Convert.ToStri ng(row["Nome"])== sNomeU){
idutente = Convert.ToInt32 (row["id"]);
}
Because I don't want to show a label with the name ( sNomeU is =
label1.tetx )

Thanks to all.
Paolol

Jul 25 '06 #2
Thanks Nicholas,
that perfect :)
No I need to get the ID of the row to use in a query that will show in a
new form/grid :)

Paolol

Nicholas Paldino [.NET/C# MVP] ha scritto:
paolol,

I assume you mean the currently selected row in a grid? If this is the
case, then what you want to do is get the binding context for the control,
and then pass the data set into it, like so:

// Get the context.
BindingContext context = dataGrid.Bindin gContext;

// Get the currency manager.
BindingManagerB ase manager = context[dataSet, memberName];

// Get the current row view.
DataRowView rowView = (DataRowView) manager.Current ;

// Get the row.
DataRow row = rowView.Row;

A few things to point out. The first parameter of the call to the
indexer for BindingContext needs to be the DataSource and the DataMember of
the data source. For example, if you bound the grid to the DataTable
directly, then just use that. If you bound to the DataSet and specified the
table name as the DataMember, then pass the data set and the member name.

You can also access the values in the row using the DataRowView.

Finally, you might just want to bind the text of the label to the
datasource directly. This is easier than setting it yourself when the
current selection changes.

Hope this helps.

Jul 25 '06 #3

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

Similar topics

2
2266
by: George Grodentzik | last post by:
I created a typed dataset from which I am trying to access the data. When I use the following code to access a row string name =dataset.person.firstName I receive an error System.IndexOutOfRangeException as if there are no rows. Yet when I dump the data to a file I receive (sample of file) <?xml version="1.0" standalone="yes"?><Dataset1 xmlns="http://tempuri.org/Dataset1.xsd"><Table><accountNo>1</accountNo><firstName>John ...
3
14736
by: DonRex | last post by:
Hello all! I couldn't find a web application-newsgroup for ASP.NET, so I'm sorry if this is the wrong forum! Synopsis: In my webform I have 3 nested repeaters: rpWeeks ----- rpTime
4
4890
by: Eugen Walcher | last post by:
Hello all, I've tried posting this same question on other newsgroups with no luck. This group seems to have a lot more activity so I apologize if you have seen it before. I'm trying to create a web service in c# using paradox data. The data is stored locally on my development machine with IIS also installed. Web services are working to the point where I can return strings and ints using Access2000 data but whenever I try and...
5
2679
by: DC Gringo | last post by:
I have a dropdownlist that, upon form submission, I'd like to maintain the selected value when I get my result...how do I do that? <asp:dropdownlist Font-Size="8" id="ddlCommunities" runat="server" Width="100"></asp:dropdownlist> Sub RunReport_OnClick(sender As Object, e As System.EventArgs) _sqlStmt &= " AND tblSurvey1.clnGUID = '" &
3
26356
by: Stephen Adam | last post by:
Hi there, I'm sure i'm missing something really simple here, all i want to do is get the value of the selected item in a list box. Even after much fiddling about last night I still could not get my code to work. Below is some code which highlights my problem. All I want to do is set the lable control's text property to the value of the selected drop down list value - in this example i've shown the three ways i've tried. Please help!
0
1587
by: N. Demos | last post by:
Hello, I'm having problems accessing a complex XML child node (latitude & longitude), and passing it to a function when the XML file has been read into a DataSet. Specifically, the returned object from accessing the 'latitude' and 'longitude' nodes is not a DataTable (as specified in the MSDN). I'm not sure what type is being returned, nor how to go about finding out. Any pointers would be appreciated. Below is the relevent Error message,...
3
1431
by: CJ | last post by:
I have a page with a bunch of iframes (which make up a tab control). At least one of these iframes contains an aspx page, which in turn contains a .ascx component. This component then contains a datagrid. Is there any way that I can access this datagrid from one of the other iframes? The grid contains a template column containing checkboxes, and I need to access the rows for which the checkbox is selected from this other iframe. Since...
4
6157
by: rn5a | last post by:
I am binding a DropDownList with records existing in a database table. I want to add an extra item *SELECT COMPANY* at index 0 so that by default, it gets selected. This is how I tried it but the extra item just doesn't get added to the DropDownList: ============================================= <script runat="server"> Sub Page_Load(..........) Dim dSet As DataSet Dim sqlConn As SqlConnection
0
1272
by: waldedg | last post by:
I have a ListBox set as Multiselect. I am populating the table thruough asp.net code. But I am using another dataset to get the items that should be selected. The only item that ends up selected is the last item in the dataset. The code I am using for setting the selected items is: DataSet ds1 = SqlHelper.ExecuteDataset(ConnStr, "StoredProd", Parm); lbRequestTime.SelectionMode = ListSelectionMode.Multiple; ...
0
10134
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
9963
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
11525
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
11110
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11293
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9858
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
8218
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
7389
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
4447
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.