Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. viewstate of dynamic text boxs

viewstate of dynamic text boxs

Scheduled Pinned Locked Moved ASP.NET
question
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    test 09
    wrote on last edited by
    #1

    private void Descriptiontable()
    {

        DescriptionClass dcss = new DescriptionClass();
        dcss.ProjectIDp = Convert.ToInt32(Session\["ProjectId"\].ToString());
        // dcss.ProjectIDp = Convert.ToInt32(ProjectIDText.Text);
        DataSet ds = new DataSet();
        dtDesc = dcss.DynamicDataSet().Tables\[0\];
    
        dtDesc.Columns.Add("DescriptionName1");
        dtDesc.Columns.Add("Date1");
        dtDesc.Columns.Add("Description1");
        int intID = 1;
        foreach (DataRow drow in dtDesc.Rows)
        {
            drow\["ProjectID"\] = intID++;
            drow\["DescriptionName1"\] = "qwe";
            drow\["Date1"\] = "";
            drow\["Description1"\] = "asdasd";
        }
        Session\["dtDesc"\] = dtDesc;
        if (dtDesc.Rows.Count == 0)
        {
            adddescription();
        }
        else
        {
            Bindrepeater();
        }
    }
    
    private void adddescription()
    {
        dtDesc = (DataTable)Session\["dtDesc"\];
        DataRow descRow = dtDesc.NewRow();
        //  descRow\["ProjectID"\] = dtDesc.Rows.Count + 1;
        descRow\["DescriptionName"\] = "";
        descRow\["Date"\] ="";
        descRow\["Description"\] = "";
        dtDesc.Rows.Add(descRow);
        Session\["dtDesc"\] = dtDesc;
        Bindrepeater();
    }
    
    private void Bindrepeater()
    {
        if (Session\["dtDesc"\] == null)
        {
            Descriptiontable();
        }
        dtDesc = (DataTable)Session\["dtDesc"\];
        DataView dv = dtDesc.DefaultView;
        if (dv.Count == 0)
        {
            adddescription();
        }
        Rptdescription.DataSource = dv;
        Rptdescription.DataBind();
    }
    

    //button click event
    adddescription();

    This is how im creating dynamic textboxes in repeater... But how do i store viewstate of those textboxs on btnclick event... so that values of text boxs may not dissappear on post back....

    A 1 Reply Last reply
    0
    • T test 09

      private void Descriptiontable()
      {

          DescriptionClass dcss = new DescriptionClass();
          dcss.ProjectIDp = Convert.ToInt32(Session\["ProjectId"\].ToString());
          // dcss.ProjectIDp = Convert.ToInt32(ProjectIDText.Text);
          DataSet ds = new DataSet();
          dtDesc = dcss.DynamicDataSet().Tables\[0\];
      
          dtDesc.Columns.Add("DescriptionName1");
          dtDesc.Columns.Add("Date1");
          dtDesc.Columns.Add("Description1");
          int intID = 1;
          foreach (DataRow drow in dtDesc.Rows)
          {
              drow\["ProjectID"\] = intID++;
              drow\["DescriptionName1"\] = "qwe";
              drow\["Date1"\] = "";
              drow\["Description1"\] = "asdasd";
          }
          Session\["dtDesc"\] = dtDesc;
          if (dtDesc.Rows.Count == 0)
          {
              adddescription();
          }
          else
          {
              Bindrepeater();
          }
      }
      
      private void adddescription()
      {
          dtDesc = (DataTable)Session\["dtDesc"\];
          DataRow descRow = dtDesc.NewRow();
          //  descRow\["ProjectID"\] = dtDesc.Rows.Count + 1;
          descRow\["DescriptionName"\] = "";
          descRow\["Date"\] ="";
          descRow\["Description"\] = "";
          dtDesc.Rows.Add(descRow);
          Session\["dtDesc"\] = dtDesc;
          Bindrepeater();
      }
      
      private void Bindrepeater()
      {
          if (Session\["dtDesc"\] == null)
          {
              Descriptiontable();
          }
          dtDesc = (DataTable)Session\["dtDesc"\];
          DataView dv = dtDesc.DefaultView;
          if (dv.Count == 0)
          {
              adddescription();
          }
          Rptdescription.DataSource = dv;
          Rptdescription.DataBind();
      }
      

      //button click event
      adddescription();

      This is how im creating dynamic textboxes in repeater... But how do i store viewstate of those textboxs on btnclick event... so that values of text boxs may not dissappear on post back....

      A Offline
      A Offline
      Arun Jacob
      wrote on last edited by
      #2

      Where you are creating dynamic textboxes in this code? Or you defined static html inside Repeater?

      Arun Jacob http://codepronet.blogspot.com/

      T 1 Reply Last reply
      0
      • A Arun Jacob

        Where you are creating dynamic textboxes in this code? Or you defined static html inside Repeater?

        Arun Jacob http://codepronet.blogspot.com/

        T Offline
        T Offline
        test 09
        wrote on last edited by
        #3

        yes ststic html defined..

        <asp:Repeater ID="Rptdescription" OnItemCommand="Rptdescription_ItemCommand" runat="server">
        <HeaderTemplate>

        </HeaderTemplate>
        <ItemTemplate>
        <tr style="width:100%">
        <td colspan=16>
        Description Name/Type & Source  <asp:TextBox CssClass="input" ID="TextName" Width="240px" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "DescriptionName") %>'></asp:TextBox>
        <!-- <asp:Label ID="TxtName" runat="server" Visible="false" Text='<%# DataBinder.Eval(Container.DataItem, "DescriptionName") %>'></asp:Label>
        --></td> <td colspan=8>
        <!--<asp:Label ID="TxtDate" runat="server" Visible="false" Text='<%# DataBinder.Eval(Container.DataItem, "Date") %>'></asp:Label>
        -->Date  <asp:TextBox ID="TextDate" runat="server" Text='<%# string.Format("{0:dd/MM/yyyy}",Eval("Date")) %>'></asp:TextBox>

            <cc1:CalendarExtender Format="dd/MM/yyyy"  ID="CalendarExtender1" runat="server"  TargetControlID="TextDate" PopupButtonID="ImageButton1"  >
            </cc1:CalendarExtender>
            <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/Calendar\_scheduleHS.png" ValidationGroup="false" />
           <br /> <asp:RegularExpressionValidator ID="RegularExpressionValidator14" runat="server" ValidationExpression="(0\[1-9\]|\[12\]\[0-9\]|3\[01\])\[- /.\](0\[1-9\]|1\[012\])\[- /.\](19|20)\\d\\d" Display="Dynamic"  ControlToValidate="TextDate" ErrorMessage="Please Enter in dd/mm/yyyy format"></asp:RegularExpressionValidator>
        
        
           
         </td> 
         </tr>
         <tr style="width:100%">
         <td colspan=20 >
        <!--      <asp:Label ID="TxtDescription" Visible="false" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Description") %>'></asp:Label>
        

        --> <asp:TextBox CssClass="input" ID="TextDescript" TextMode="MultiLine" Columns="70" Rows="5" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Description") %>'></asp:TextBox>
        </td>
        <td><asp:LinkButton ID="delete" CommandName="Delete" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "id") %>' ValidationGroup="false" runat="server">delete</asp:LinkButton></td>
        </tr>
        </ItemTemplate>
        <FooterTemplate>
        </FooterTemplate>
        </as

        A 1 Reply Last reply
        0
        • T test 09

          yes ststic html defined..

          <asp:Repeater ID="Rptdescription" OnItemCommand="Rptdescription_ItemCommand" runat="server">
          <HeaderTemplate>

          </HeaderTemplate>
          <ItemTemplate>
          <tr style="width:100%">
          <td colspan=16>
          Description Name/Type & Source  <asp:TextBox CssClass="input" ID="TextName" Width="240px" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "DescriptionName") %>'></asp:TextBox>
          <!-- <asp:Label ID="TxtName" runat="server" Visible="false" Text='<%# DataBinder.Eval(Container.DataItem, "DescriptionName") %>'></asp:Label>
          --></td> <td colspan=8>
          <!--<asp:Label ID="TxtDate" runat="server" Visible="false" Text='<%# DataBinder.Eval(Container.DataItem, "Date") %>'></asp:Label>
          -->Date  <asp:TextBox ID="TextDate" runat="server" Text='<%# string.Format("{0:dd/MM/yyyy}",Eval("Date")) %>'></asp:TextBox>

              <cc1:CalendarExtender Format="dd/MM/yyyy"  ID="CalendarExtender1" runat="server"  TargetControlID="TextDate" PopupButtonID="ImageButton1"  >
              </cc1:CalendarExtender>
              <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/Calendar\_scheduleHS.png" ValidationGroup="false" />
             <br /> <asp:RegularExpressionValidator ID="RegularExpressionValidator14" runat="server" ValidationExpression="(0\[1-9\]|\[12\]\[0-9\]|3\[01\])\[- /.\](0\[1-9\]|1\[012\])\[- /.\](19|20)\\d\\d" Display="Dynamic"  ControlToValidate="TextDate" ErrorMessage="Please Enter in dd/mm/yyyy format"></asp:RegularExpressionValidator>
          
          
             
           </td> 
           </tr>
           <tr style="width:100%">
           <td colspan=20 >
          <!--      <asp:Label ID="TxtDescription" Visible="false" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Description") %>'></asp:Label>
          

          --> <asp:TextBox CssClass="input" ID="TextDescript" TextMode="MultiLine" Columns="70" Rows="5" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Description") %>'></asp:TextBox>
          </td>
          <td><asp:LinkButton ID="delete" CommandName="Delete" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "id") %>' ValidationGroup="false" runat="server">delete</asp:LinkButton></td>
          </tr>
          </ItemTemplate>
          <FooterTemplate>
          </FooterTemplate>
          </as

          A Offline
          A Offline
          Arun Jacob
          wrote on last edited by
          #4

          Okay.Then before creating new row and binding it to repeater, you need to save the edited data in text boxes to some persisting object.

          Arun Jacob http://codepronet.blogspot.com/

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups