Actual position of a row

G

Guest

Hi

I have a dataset whose view I bind to a datagrid. I sort this datagrid in different ways. Is it possible to find out the actual position of a row in the dataset from this dataview? If yes, how

Thanks for all inputs

Benny
 
G

Guest

Use the BindingContext property for the control, pass the dataset/datatable to which you have bound the control to, and then use the Position property

Eg: this.BindingContext[MyDataset11].Positio
where this would represent the instance of some control

HTH
fbhcah
 
M

Mohamoss

Hi Benny

if your application is a webapp , another way it to define a
datakeyfiled ... it shoud be the primary key of the table of the dataset
using this you can get the row inside the dataset , what you
will be doing is ..... get the primary key value "from the selected row of
the datagrid" , then use it to get a referece to the row inside the
dataset.... you can write code like this in the command item event handler
of a datagird to change value in the correspondent row inside the database
...
private void DataGrid1_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{

DataRow row =
mydataset.mytable.Rows.Find(DataGrid1.DataKeys[e.Item.ItemIndex]);
//now that you got the row , you can do all the modifications on it
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top