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

I have gridview and button out side. for gridview i have autogenerate columns true it was dynamicllay change as per the roles so different grids will appear.i will bind the grid structure as follows(note it might chage as per the roles)

SNo  Name     Address
1    kerrthi   hyderabad

i am showing the gridview in label and in row data bound i was doing
C#
TextBox tb = new TextBox();
RequiredFieldValidator rfv = new RequiredFieldValidator();
tb.Text = string.Empty;
if (grvInsuranceDetails.HeaderRow.Cells[i].Text == "IE_VECHICLE_MAP") { 
    tb.Enabled = false;
    tb.Text = ViewState["IE_Vehiclecode"].ToString();
}
tb.ID = "txtbox" + i.ToString();
rfv.ID = "rfvvalid" + i.ToString();
rfv.ControlToValidate = tb.ID;
rfv.ErrorMessage = "*";
rfv.ForeColor = System.Drawing.Color.Red;
rfv.ValidationGroup = "required";
tb.Style.Add("Width", "120px");
tb.Style.Add("Height", "15px");
tb.Attributes.Add("runat", "Server");
//c.Controls.Clear();
//c.RowSpan
grdviewvechicleDetails.Controls.Add(tb);
c.Controls.Add(tb);
c.Controls.Add(rfv);
i++;


in submit button click i was not able the find the text box id it was showing as null

C#
foreach (GridViewRow grv in grvInsuranceDetails.Rows)
            {
                int i = 0;
                   TextBox txt = (TextBox)grv.FindControl("txtbox1");
                    foreach (TableCell c in grv.Cells)
                    {
                        TextBox txt1 = (TextBox)c.FindControl("txtbox0");
                        string grdid = grvInsuranceDetails.Rows[grv.RowIndex].Cells[i].Text.ToString().TrimEnd();
                        i++;
                    }
            } 


Can anybody help me with this?

Thanks in advance!
Posted
Updated 6-Mar-14 1:37am
v3
Comments
Krunal Rohit 6-Mar-14 7:57am    
Well you code looks to be promising but still put a breakpoint and see.

-KR

1 solution

Are you rebinding the GridView on postback (and prior to the click event firing)? The dynamically added controls won't be a part of the control tree if you don't and FindControl won't be able to find them.
 
Share this answer
 

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

  Print Answers RSS


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