datagrid, paging and editcommand colum

V

Venkat Chellam

I have a datagrid in my page which has one editcommandcolumn with
edit, update and cancel options. Paging is also enabled in my
datagrid. When viewing data the paging works fine but when move to
next page and then click edit link of the editcommand column for the
1st row,it doesn't make that row editable and nothing happens.

i trapped the event in on_editcommand event and when i check
DataGridCommand args, the paramter e, it has the itemindex at 0. I am
expecting the itemindex at 10 as its the first item in the second page
and each page has 10 items.
Can someone help me?

venky
 
S

Scott M.

Having an edit button or link doesn't put you into edit mode. In the
EditCommand event handler, add:

DataGrid.EditItemIndex = e.item.itemindex

In the CancelCommand event handler add:

DataGrid.EditItemIndex = -1
 
V

venkat chellam

I have this code in my events scot, but it works fine only for the first
page but if click next to go to next 10 records and try to edit the
first record , it doesn't put it in edit mode and when i trapped
e.item.itemindex, it shows as 0, i am expecting it to be shown as 10

venky
 
V

venkat chellam

Following is my editcommand event

private void myDataGrid_EditCommand_1(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
try
{
if(myDataGrid.EditItemIndex != -1)
return;
myDataGrid.EditItemIndex=
myDataGrid.CurrentPageIndex*myDataGrid.PageSize)
+ e.Item.ItemIndex;

string scriptblockLoad = "<script
language='javascript'> window.Form1.submit
();;</script>";
Page.RegisterStartupScript
("LOAD_WINDOW",scriptblockLoad);

}


following is my cancelcommand event


private void myDataGrid_CancelCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
myDataGrid.EditItemIndex= -1;


}
 
S

Scott M.

But I do have a comment on this:

if(myDataGrid.EditItemIndex != -1)
return;
myDataGrid.EditItemIndex=
myDataGrid.CurrentPageIndex*myDataGrid.PageSize)
+ e.Item.ItemIndex;

There is no need to check to see if the EditItemIndex is -1 - that doesn't
matter, so I'd take it out.
But, why are you setting the EditItemIndex equal to the CurrentPageIndex
multiplied by the PageSize plus the item index? Just do this:

myDataGrid.EditItemIndex = e.Item.ItemIndex;
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top