How to save data from dynamic text box created in grid

Last post 10-02-2007 6:03 AM by naturehermit. 4 replies.

Sort Posts:

  • How to save data from dynamic text box created in grid

    09-08-2007, 4:44 AM
    • Loading...
    • vrun_gupta
    • Joined on 09-08-2007, 8:32 AM
    • Posts 3

     

    I am creating a interface consist of grid view which consist of a lot of text boxes which i am creating dynamically on the basis of elements from  XML file.

    but when i want to save data from that interface it is giving problem to me in that.

    i am using code in this while saving is :

    foreach (GridViewRow orow in GrdDynamic.Rows)
            {
                foreach (TableCell cell in orow.Cells)
                {
                    TextBox txtBox = (TextBox)cell.Controls[0];

                    Response.Write(txtBox.Text);
                    string strtxc = txtBox.Text;
                }
                Response.Write("<BR>");
            }

    But my GrdDynamic.Rows.Count brings me answer =0;

    can anyone help me?????????????????????????????????????? 

  • Re: How to save data from dynamic text box created in grid

    09-09-2007, 9:43 AM
    • Loading...
    • joteke
    • Joined on 06-16-2002, 3:24 PM
    • Kyro, Finland
    • Posts 6,577
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs

    How's the grid built?

    Thanks,

    Teemu Keiski
    Finland, EU
  • Re: How to save data from dynamic text box created in grid

    09-10-2007, 4:19 AM
    • Loading...
    • vrun_gupta
    • Joined on 09-08-2007, 8:32 AM
    • Posts 3

    I just take a grid from toolbar but i didn't specify it's columns or rows all that things as well as text boxes  are created dynamaically from XML file I want to know that how i can able to store the values of that text boxes in database.

    Because when i am trying for that i am using code is given above. If i am doing rows.count : It is bringing result 0.

    That's my problem. 

  • Re: How to save data from dynamic text box created in grid

    10-02-2007, 4:41 AM
    • Loading...
    • rah
    • Joined on 08-12-2007, 2:15 PM
    • Posts 30

    i too searching for the code to create dynamic textbox . can u pls post the code how to create text box dynamically in gridview which will be helpful for me.

    thanks

  • Re: How to save data from dynamic text box created in grid

    10-02-2007, 6:03 AM

    vrun_gupta:

     

    I am creating a interface consist of grid view which consist of a lot of text boxes which i am creating dynamically on the basis of elements from  XML file.

    but when i want to save data from that interface it is giving problem to me in that.

    i am using code in this while saving is :

    foreach (GridViewRow orow in GrdDynamic.Rows)
            {
                foreach (TableCell cell in orow.Cells)
                {
                    TextBox txtBox = (TextBox)cell.Controls[0];

                    Response.Write(txtBox.Text);
                    string strtxc = txtBox.Text;
                }
                Response.Write("<BR>");
            }

    But my GrdDynamic.Rows.Count brings me answer =0;

    can anyone help me?????????????????????????????????????? 

    First of all what does this line mean  TextBox txtBox = (TextBox)cell.Controls[0]; (the index will return out of syn in this case anyway..and it doesnt make syntatical point as there are no controls and even if there are how can you convert?, and the other point is what about the value loss , the data bound to xml)

    but if dynamic textbox is what you want then here's the code and it works

    protected void Page_Load(object sender, EventArgs e)

    {//XML stuff as you suggested

    DataSet oDs = new DataSet();oDs.ReadXml(Request.PhysicalApplicationPath+"XMLFile.xml");

    GridView1.DataSource = oDs;

    GridView1.DataBind();

    foreach (GridViewRow orow in GridView1.Rows)

    {

    foreach (TableCell cell in orow.Cells)

    {

    {

    TextBox tbx = new TextBox();

    cell.Controls.Add(tbx);

    string strtxc = tbx.Text;

    }

    }

    Response.Write(
    "<BR>");

    }

    }

     

    Hope this is what you are looking for and the person below who wants those textboxes. sorry If i havent understood.

    Please Mark Post that helped you as answer, also include a summary of what solved the problem as it helps others in similar situations
Page 1 of 1 (5 items)
Microsoft Communities
Page view counter