Hi,
I am shwetha..
I have a Paged gridview, with pagesize 3..i,e only 3 records are displaying per page.I have added EDIT,UPDATE,CANCEL operations to each row of gridview using Templates.when i click EDIT, the editable fields of that particular row [here, i have used e.row.rowindex of RowDataBound event, to load the values to dropdown list on particular row select] are loaded with possible data values via dropdown list.
This mechanism is working fine with the first page of gridview..i,e pagenum=0.
But the same is not working fine with the second page.Because when i select EDIT operation of "first row" in the "second page" of gridview, the e.row.RowIndex value is again starting from 0..so the editable fields of that row are loading with the first page, first row data..
I want to maintain the rowindex value depending on pagesize..as i have pagesize 3..when i select EDIT operation of first row of second page..e.row.rowINDEX value must be 3...next in 3rd page the first row e.row.rowIndex value must be 6....
Please anyone help me...
aspx.cs code:
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
Session["PageNum"] = e.NewPageIndex;
PageSet = int.Parse(Session["PageNum"].ToString());
ShowGrid();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
Label lb5 = (Label)GridView1.Rows[e.RowIndex].FindControl("Label5");
Label lb6 = (Label)GridView1.Rows[e.RowIndex].FindControl("Label6");
Label lb7 = (Label)GridView1.Rows[e.RowIndex].FindControl("Label7");
DropDownList ddl1 = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("DropDownList1");
DropDownList ddl2 = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("DropDownList2");
DropDownList ddl3 = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("DropDownList3");
DropDownList ddl4 = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("DropDownList4");
Label lb12 = (Label)GridView1.Rows[e.RowIndex].FindControl("Label12");
GridView1.DataSource = data.UpdateReport(ddl1.SelectedValue.ToString(), ddl2.SelectedValue.ToString(), ddl3.SelectedValue.ToString(), ddl4.SelectedValue.ToString(), lb5.Text.ToString());
GridView1.EditIndex = -1;
ShowGrid();
lblMsg.Visible = true;
lblMsg.Text = "Updated Successfully...";
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
ListItem lt = new ListItem();
if (e.Row.RowType == DataControlRowType.DataRow)
{
if ((e.Row.RowState & DataControlRowState.Edit) > 0)
{
if (PageSet != 0)
index = (PageSet * 3) + e.Row.RowIndex;
else
index = e.Row.RowIndex;
DropDownList dp1 = (DropDownList)e.Row.FindControl("DropDownList1");
DataTable dt = data.DisplayData();
dp1.SelectedValue = dt.Rows[index][3].ToString();
DropDownList dp2 = (DropDownList)e.Row.FindControl("DropDownList2");
dp2.SelectedValue = dt.Rows[index][4].ToString();
DropDownList dp3 = (DropDownList)e.Row.FindControl("DropDownList3");
dp3.SelectedValue = dt.Rows[index][5].ToString();
DropDownList dp4 = (DropDownList)e.Row.FindControl("DropDownList4");
dp4.SelectedValue = dt.Rows[index][6].ToString();
}
}
}
protected void GridView1_PageIndexChanged(object sender, EventArgs e)
{
string direction,sortExp;
if(Set==1)
{
direction = Session["direction"].ToString();
sortExp = Session["sortExp"].ToString();
ShowSortGrid(sortExp, direction);
}
else
ShowGrid();
}