faramarz_s
دوشنبه 03 فروردین 1383, 12:30 عصر
در دیتا گریدی با امکان Paging زمانی که به صفحات جدید دیتا گرید می روم( NewPageIndex) شسن ها و نیز دسترسی به کنترلهای درون دیتا گرید مختل می شود.نمونه برنامه :
private void DataGrid1_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
//DataGrid1.DataKeys[(int)e.Item.ItemIndex]=-1;
//Label3.Text=DataGrid1.DataKeys[(int)e.Item.ItemInd ex].ToString();
//DataGrid1.DataKeys[(int)e.Item.ItemIndex] = 1;'it is read only
Session["NewsId"]=DataGrid1.DataKeys[(int)e.Item.ItemIndex];
/**/
if (((DropDownList)e.Item.FindControl("DropDownList1")).SelectedValue == "edit")
{
Response.Redirect("EditNews.aspx");
}
if (((DropDownList)e.Item.FindControl("DropDownList1")).SelectedValue == "first")
{
SetInDefaultWebForm();
Response.Redirect("../Default.aspx");
}
if (((DropDownList)e.Item.FindControl("DropDownList1")).SelectedValue == "del")
{
DelNews();
//Response.Redirect("DelNews.aspx");
}
if (((DropDownList)e.Item.FindControl("DropDownList1")).SelectedValue == "DelF")
{
RemoveFromDefaultWebForm();
Response.Redirect("../Default.aspx");
}
if (((DropDownList)e.Item.FindControl("DropDownList1")).SelectedValue == "َAdd")
{
Response.Redirect("AddNews.aspx");
}
}
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEvent Args e)
{
DataGrid1.CurrentPageIndex=e.NewPageIndex;
bindGrid1();
/*try
{
if ((DataGrid1.PageCount - e.NewPageIndex) > 0)
{
DataGrid1.CurrentPageIndex=e.NewPageIndex;
//Session["NewsId"]=DataGrid1.DataKeys[0];
bindGrid1();
}
}
catch (Exception e01)
{
Label3.Text = e01.Message.ToString();
}*/
}
عنایت بفرمایید به خطای اول:
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
Source Error:
Line 169: //Label3.Text=DataGrid1.DataKeys[(int)e.Item.ItemInd ex].ToString();
Line 170: //DataGrid1.DataKeys[(int)e.Item.ItemIndex] = 1;'it is read only
Line 171: Session["NewsId"]=DataGrid1.DataKeys[(int)e.Item.ItemIndex];
Line 172:
Line 173:
اگر احیانا سشن را کامنت کنیم:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 172:
Line 173: /**/
Line 174: if (((DropDownList)e.Item.FindControl("DropDownList1")).SelectedValue == "edit")
Line 175: {
Line 176:
برای حفظ مقادیر سشن و کنترلهای دورن دیتا گرید و رفع مشکل حاضر چه باید کرد؟
تشکر :roll:
private void DataGrid1_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
//DataGrid1.DataKeys[(int)e.Item.ItemIndex]=-1;
//Label3.Text=DataGrid1.DataKeys[(int)e.Item.ItemInd ex].ToString();
//DataGrid1.DataKeys[(int)e.Item.ItemIndex] = 1;'it is read only
Session["NewsId"]=DataGrid1.DataKeys[(int)e.Item.ItemIndex];
/**/
if (((DropDownList)e.Item.FindControl("DropDownList1")).SelectedValue == "edit")
{
Response.Redirect("EditNews.aspx");
}
if (((DropDownList)e.Item.FindControl("DropDownList1")).SelectedValue == "first")
{
SetInDefaultWebForm();
Response.Redirect("../Default.aspx");
}
if (((DropDownList)e.Item.FindControl("DropDownList1")).SelectedValue == "del")
{
DelNews();
//Response.Redirect("DelNews.aspx");
}
if (((DropDownList)e.Item.FindControl("DropDownList1")).SelectedValue == "DelF")
{
RemoveFromDefaultWebForm();
Response.Redirect("../Default.aspx");
}
if (((DropDownList)e.Item.FindControl("DropDownList1")).SelectedValue == "َAdd")
{
Response.Redirect("AddNews.aspx");
}
}
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEvent Args e)
{
DataGrid1.CurrentPageIndex=e.NewPageIndex;
bindGrid1();
/*try
{
if ((DataGrid1.PageCount - e.NewPageIndex) > 0)
{
DataGrid1.CurrentPageIndex=e.NewPageIndex;
//Session["NewsId"]=DataGrid1.DataKeys[0];
bindGrid1();
}
}
catch (Exception e01)
{
Label3.Text = e01.Message.ToString();
}*/
}
عنایت بفرمایید به خطای اول:
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
Source Error:
Line 169: //Label3.Text=DataGrid1.DataKeys[(int)e.Item.ItemInd ex].ToString();
Line 170: //DataGrid1.DataKeys[(int)e.Item.ItemIndex] = 1;'it is read only
Line 171: Session["NewsId"]=DataGrid1.DataKeys[(int)e.Item.ItemIndex];
Line 172:
Line 173:
اگر احیانا سشن را کامنت کنیم:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 172:
Line 173: /**/
Line 174: if (((DropDownList)e.Item.FindControl("DropDownList1")).SelectedValue == "edit")
Line 175: {
Line 176:
برای حفظ مقادیر سشن و کنترلهای دورن دیتا گرید و رفع مشکل حاضر چه باید کرد؟
تشکر :roll: