Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI I write this code:
(System.Web.UI.WebControls.HiddenField)(GridViewOptional.Rows[i].Cells[1].FindControl("HiddenField1"))).Value.ToString()
And this field one of the Gridview field and i need it but my Gridview have paging and a code that discribe in above have problem when it want to read a Cell in another pageing of gridview,,,a mean when it want read information from another page have this error:Index was out of range. Must be non-negative and less than the size of the collection.
Please help me to solve it.
Posted
Comments
rahkan 19-Dec-12 6:55am    
when you have a gridview that uses paging the only data available in the gridview is current page's data. Any other page of the GridView is simply not available. You either need to store the value you want outside of the gridview or get it from the database or wherever the data is coming from
omidfarvaha 19-Dec-12 7:09am    
Thank you I don't know this,,,, but my code have loop and must check All of Cell about up code What can I do? my complete code is:
protected void lnkAddoptional_Click(object sender, EventArgs e)
{
LinkButton lnkbtn = sender as LinkButton;
//getting particular row linkbutton
GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;
// //getting userid of particular row
string eno = GridViewOptional.DataKeys[gvrow.RowIndex].Value.ToString();
// // string Coursename = gvrow.Cells[0].Text;
DataTable Temp = new DataTable();
Temp.Clear();
Temp = Session["Select_optional"] as DataTable;
for (int i = 0; i <= Temp.Rows.Count - 1; i++)
{

DataRow dr;
if (((System.Web.UI.WebControls.HiddenField)(GridViewOptional.Rows[i].Cells[1].FindControl("HiddenField1"))).Value.ToString() == Convert.ToString(eno))
{
string ProductId = ((HiddenField)GridViewOptional.Rows[i].Cells[0].FindControl("HiddenField1")).Value;
Label Cost = (Label)GridViewOptional.Rows[i].Cells[1].FindControl("LblCost");
Label lbldscribe = (Label)GridViewOptional.Rows[i].Cells[2].FindControl("Labeldiscribe");
DataRow row = Second_Sel.NewRow();

row[0] = lbldscribe.Text;
row[1] = Cost.Text;
row[2] = ProductId;
Second_Sel.Rows.Add(row);
dr = Temp.Rows[i];
Temp.Rows[i].Delete();
}
}
a mean I have linkBotton in first Gridview and I want to when click on linkbotton from first Gridview data transfer to second Gridview and delete from first gridview and I have not any database justlike sql and I just work with datatable and I have to check all of field but some field in another page of gridview and have a Error that i discribe in my question what canI do?
AshishChaudha 19-Dec-12 7:00am    
What you are doing?? Please share your code.
omidfarvaha 19-Dec-12 7:10am    
I Share my code please help me
omidfarvaha 19-Dec-12 7:12am    
Thank you I don't know this,,,, but my code have loop and must check All of Cell about up code What can I do? my complete code is: protected void lnkAddoptional_Click(object sender, EventArgs e) { LinkButton lnkbtn = sender as LinkButton; //getting particular row linkbutton GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow; // //getting userid of particular row string eno = GridViewOptional.DataKeys[gvrow.RowIndex].Value.ToString(); // // string Coursename = gvrow.Cells[0].Text; DataTable Temp = new DataTable(); Temp.Clear(); Temp = Session["Select_optional"] as DataTable; for (int i = 0; i <= Temp.Rows.Count - 1; i++) { DataRow dr; if (((System.Web.UI.WebControls.HiddenField)(GridViewOptional.Rows[i].Cells[1].FindControl("HiddenField1"))).Value.ToString() == Convert.ToString(eno)) { string ProductId = ((HiddenField)GridViewOptional.Rows[i].Cells[0].FindControl("HiddenField1")).Value; Label Cost = (Label)GridViewOptional.Rows[i].Cells[1].FindControl("LblCost"); Label lbldscribe = (Label)GridViewOptional.Rows[i].Cells[2].FindControl("Labeldiscribe"); DataRow row = Second_Sel.NewRow(); row[0] = lbldscribe.Text; row[1] = Cost.Text; row[2] = ProductId; Second_Sel.Rows.Add(row); dr = Temp.Rows[i]; Temp.Rows[i].Delete(); } } a mean I have linkBotton in first Gridview and I want to when click on linkbotton from first Gridview data transfer to second Gridview and delete from first gridview and I have not any database justlike sql and I just work with datatable and I have to check all of field but some field in another page of gridview and have a Error that i discribe in my question what canI do?

1 solution

are you doing this in edit mode?
 
Share this answer
 
Comments
omidfarvaha 19-Dec-12 7:16am    
Yes,,But haven'ta good result
Faisalabadians 19-Dec-12 7:34am    
dear, I have been gone through the problem, you are facing now. I could not found any solution to it, then I added an other page for edit, used ajax modal popup extender with iframe to achieve target. if you found any good solution, please let me know at craze.programmer@gmail.com

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900