Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a grid with dynamic rows and columns.In each row I have an Button Called as "Notify". On clicking Button I want to bind text box value to a label in the grid. I have coded as below.....
On Butto_Click
{
GridViewRow row = (GridViewRow)(((Button)e.CommandSource).NamingContainer);
TextBox txtItemDescription = (TextBox)row.FindControl("txtItemDescription");
Label lbl = (Label)row.FindControl("lblItem");
lbl.Text = txtItemDescription.Text;
txtItemDescription.Visible = false;
txtItemDescription.Text = string.Empty;
SetPreviousData();
}



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 txtItemDescription =
(TextBox)grdRequestResponse.Rows[rowIndex].Cells[1].FindControl("txtItemDescription");
Label lblItem =
(Label)grdRequestResponse.Rows[rowIndex].Cells[1].FindControl("lblItem");
DropDownList ddlItemAssignedto =
(DropDownList)grdRequestResponse.Rows[rowIndex].Cells[2].FindControl("ddlItemAssignedto");
TextBox txtDateCompleted =
(TextBox)grdRequestResponse.Rows[rowIndex].Cells[3].FindControl("txtDateCompleted");


RadioButtonList rdbListCompletedasPlanned =
(RadioButtonList)grdRequestResponse.Rows[rowIndex].Cells[4].FindControl("rdbListCompletedasPlanned");

Label lblSignature =
(Label)grdRequestResponse.Rows[rowIndex].Cells[5].FindControl("lblSignature");
TextBox txtComments =
(TextBox)grdRequestResponse.Rows[rowIndex].Cells[6].FindControl("txtComments");

grdRequestResponse.Rows[i].Cells[0].Text = Convert.ToString(i + 1);


if (lblItem.Text != string.Empty)
{
txtItemDescription.Visible = false;
lblItem.Text = dt.Rows[i]["Col1"].ToString();
}
else
{
txtItemDescription.Text = dt.Rows[i]["Col1"].ToString();
}
if (dt.Rows[i]["Col2"] != null) ddlItemAssignedto.SelectedValue = dt.Rows[i]["Col2"].ToString();
if (dt.Rows[i]["Col3"] != null) txtDateCompleted.Text = dt.Rows[i]["Col3"].ToString();
if (dt.Rows[i]["Col4"] != null) rdbListCompletedasPlanned.SelectedValue = dt.Rows[i]["Col4"].ToString();
if (dt.Rows[i]["Col5"] != null) lblSignature.Text = dt.Rows[i]["Col5"].ToString();
if (dt.Rows[i]["Col6"] != null) txtComments.Text = dt.Rows[i]["Col6"].ToString();
rowIndex++;
}
}

}
}


And Im facing a proble that....on first row click it is binding value...
but in second row while im clicking "Notify" button first label is converting as an text box....
I want to bind the textbox value to lable ever if I Click button
Posted

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