Click here to Skip to main content
15,077,054 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
private void SetPreviousData()
{

int rowIndex = 0;
if (ViewState["CurrentTable"] != null)
{
DataTable dt = (DataTable)ViewState["CurrentTable"];
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{

TextBox boxDatePosted = (TextBox)NewGridView.Rows[i].Cells[1].FindControl("txtDatePosted");//names given on aspx design
TextBox boxCheckNumber = (TextBox)NewGridView.Rows[i].Cells[2].FindControl("txtCheckNumber");
TextBox boxCheckAmount = (TextBox)NewGridView.Rows[i].Cells[3].FindControl("txtCheckAmount");
DropDownList ddl1 = (DropDownList)NewGridView.Rows[i].Cells[4].FindControl("ddlIsDeposits");


//Fill the DropDownList with Data
FillDropDownList(ddl1);
int SetRowData1 = (int) ViewState["SetRowData"];

if (i < dt.Rows.Count - 1)
{

//Assign the value from DataTable to the TextBox
boxDatePosted.Text = dt.Rows[i]["DatePosted"].ToString();
boxCheckNumber.Text = dt.Rows[i]["CheckNumber"].ToString();
boxCheckAmount.Text = dt.Rows[i]["CheckAmount"].ToString();

//Set the Previous Selected Items on Each DropDownList on Postbacks
ddl1.ClearSelection();
ddl1.Items.FindByText(dt.Rows[i]["IsDeposits"].ToString()).Selected = true;

}



rowIndex++;
}
}
}

ViewState["SetRowData"] = 0;
}
Posted
Comments
Member 11846323 18-Jul-15 12:19pm
   
My gridview has page size=3. I am getting Index out of range error, when I am adding the 4th row to my grid view. Please provide me the required solution
[no name] 19-Jul-15 8:05am
   
please, add row to the DataSource, don't change rows directly in the Grid. than call rebuild() the Grid. Also don't forget to update the TotalRows property of the Grid.

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