473,326 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

How to show table dynamically related to value entered in textbox

hi all
below is the code in aspx page which has a tablewith id=rav
so what i want is i have a texbox and button control if i enter some value in textbox( ie users choice) and click on button the value how much ihave entered that much tables should be displayed

so any body give me any examples or give me any idea





Expand|Select|Wrap|Line Numbers
  1. <form id="form1" runat="server"> <table class="auto-style1" id="rav" runat="server"> <tr> <td class="auto-style2">  Children first name </td> <td class="auto-style31"> <asp:TextBox ID="TextBox7" runat="server" CssClass="auto-style37" Width="185px"></asp:TextBox> </td> </tr> <tr> <td class="auto-style2"> <span class="auto-style18">Children last name  </span></td> <td class="auto-style33"> <asp:TextBox ID="TextBox8" runat="server" CssClass="auto-style37" Width="186px"></asp:TextBox> </td> </tr> <tr> <td class="auto-style2"> <span class="auto-style18"> Going to school?: </span></td> <td class="auto-style35"> <span class="auto-style18"> </span> <asp:RadioButton ID="RadioButton1" runat="server" CssClass="auto-style18" Text="Yes" /> <asp:RadioButton ID="RadioButton2" runat="server" CssClass="auto-style18" Text="No" /> </td> </tr> <tr> <td class="auto-style2"> <span class="auto-style18">school name : </span></td> <td class="auto-style31"> <asp:TextBox ID="TextBox9" runat="server" CssClass="auto-style38" Width="147px"></asp:TextBox> </td> </tr> <tr> <td class="auto-style2"> <span class="auto-style18">Grade :</span></td> <td class="auto-style33"> <asp:DropDownList ID="DropDownList1" cssClass="select" AutoPostBack="True" runat="server"> <asp:ListItem>1st Grade</asp:ListItem> <asp:ListItem>2nd Grade</asp:ListItem> <asp:ListItem>3rd Grade</asp:ListItem> <asp:ListItem>4th Grade</asp:ListItem> <asp:ListItem>5th Grade</asp:ListItem> </asp:DropDownList> </td> </tr> <td><asp:Button ID="Button1" runat="server" Text="save" /> </table> <asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged"></asp:TextBox> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /> </form>
Oct 12 '15 #1
1 1765
adriancs
122 100+
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html>
  2.  
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5.     <title></title>
  6.     <style type="text/css">
  7.         table{
  8.             border-collapse: collapse;
  9.         }
  10.         th, td{
  11.             border: 1px solid black;
  12.             padding: 5px;
  13.         }
  14.     </style>
  15. </head>
  16. <body>
  17.     <form id="form1" runat="server">
  18.  
  19.         <asp:Panel ID="Panel1" runat="server">
  20.             Number of Records <asp:TextBox runat="server" ID="txtNoRecords" Text="5"></asp:TextBox>
  21.             <asp:Button ID="btGetRow" runat="server" Text="Get Rows" OnClick="btGetRow_Click" />
  22.             <br />
  23.             <br />
  24.             <asp:Button ID="btSave" runat="server" Text="Save Data" OnClick="btSave_Click" />
  25.             <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
  26.                 <Columns>
  27.                     <asp:BoundField DataField="ID" HeaderText="ID" />
  28.                     <asp:TemplateField HeaderText="First Name">
  29.                         <ItemTemplate>
  30.                             <asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
  31.                         </ItemTemplate>
  32.                     </asp:TemplateField>
  33.                     <asp:TemplateField HeaderText="Last Name">
  34.                         <ItemTemplate>
  35.                             <asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
  36.                         </ItemTemplate>
  37.                     </asp:TemplateField>
  38.                     <asp:TemplateField HeaderText="Go To School">
  39.                         <ItemTemplate>
  40.                             <asp:DropDownList runat="server" ID="dropGoToSchool">
  41.                                 <asp:ListItem Value="Yes">Yes</asp:ListItem>
  42.                                 <asp:ListItem Value="No">No</asp:ListItem>
  43.                             </asp:DropDownList>
  44.                         </ItemTemplate>
  45.                     </asp:TemplateField>
  46.                     <asp:TemplateField HeaderText="School Name">
  47.                         <ItemTemplate>
  48.                             <asp:TextBox runat="server" ID="txtSchoolName"></asp:TextBox>
  49.                         </ItemTemplate>
  50.                     </asp:TemplateField>
  51.                     <asp:TemplateField HeaderText="Grade">
  52.                         <ItemTemplate>
  53.                             <asp:DropDownList ID="dropGrade" runat="server">
  54.                                 <asp:ListItem>1st Grade</asp:ListItem>
  55.                                 <asp:ListItem>2nd Grade</asp:ListItem>
  56.                                 <asp:ListItem>3rd Grade</asp:ListItem>
  57.                                 <asp:ListItem>4th Grade</asp:ListItem> 
  58.                                 <asp:ListItem>5th Grade</asp:ListItem>
  59.                             </asp:DropDownList>
  60.                         </ItemTemplate>
  61.                     </asp:TemplateField>
  62.                 </Columns>
  63.             </asp:GridView>
  64.         </asp:Panel>
  65.  
  66.         <asp:Panel ID="Panel2" runat="server" Visible="false">
  67.             Result:
  68.             <asp:GridView ID="GridView2" runat="server"></asp:GridView>
  69.         </asp:Panel>
  70.  
  71.     </form>
  72. </body>
  73. </html>
Code Behind:

Expand|Select|Wrap|Line Numbers
  1. public partial class WebForm1 : System.Web.UI.Page
  2. {
  3.     DataTable dt
  4.     {
  5.         get
  6.         {
  7.             return (DataTable)ViewState["dt"];
  8.         }
  9.         set
  10.         {
  11.             ViewState["dt"] = value;
  12.         }
  13.     }
  14.  
  15.     protected void Page_Load(object sender, EventArgs e)
  16.     {
  17.  
  18.     }
  19.  
  20.     void CreateTable()
  21.     {
  22.         if (dt == null)
  23.         {
  24.             dt = new DataTable();
  25.             dt.Columns.Add("ID");
  26.             dt.Columns.Add("First Name");
  27.             dt.Columns.Add("Last Name");
  28.             dt.Columns.Add("Go To School");
  29.             dt.Columns.Add("School Name");
  30.             dt.Columns.Add("Grade");
  31.         }
  32.     }
  33.  
  34.     void LoadForm()
  35.     {
  36.         GridView1.DataSource = dt;
  37.         GridView1.DataBind();
  38.  
  39.         for (int i = 0; i < dt.Rows.Count; i++)
  40.         {
  41.             GridViewRow gr = GridView1.Rows[i];
  42.             DataRow dr = dt.Rows[i];
  43.             ((TextBox)gr.FindControl("txtFirstName")).Text = dr["First Name"] + "";
  44.             ((TextBox)gr.FindControl("txtLastName")).Text = dr["Last Name"] + "";
  45.             ((DropDownList)gr.FindControl("dropGoToSchool")).SelectedValue = dr["Go To School"] + "";
  46.             ((TextBox)gr.FindControl("txtSchoolName")).Text = dr["School Name"] + "";
  47.             ((DropDownList)gr.FindControl("dropGrade")).SelectedValue = dr["Grade"] + "";
  48.         }
  49.     }
  50.  
  51.     void GenerateResult()
  52.     {
  53.         GridView2.DataSource = dt;
  54.         GridView2.DataBind();
  55.     }
  56.  
  57.     protected void btGetRow_Click(object sender, EventArgs e)
  58.     {
  59.         CreateTable();
  60.  
  61.         int totalRows = 0;
  62.         int.TryParse(txtNoRecords.Text, out totalRows);
  63.         txtNoRecords.Text = totalRows.ToString();
  64.  
  65.         while (dt.Rows.Count < totalRows)
  66.         {
  67.             DataRow dr = dt.NewRow();
  68.             dt.Rows.Add(dr);
  69.         }
  70.  
  71.         while (dt.Rows.Count > totalRows)
  72.         {
  73.             dt.Rows.RemoveAt(dt.Rows.Count - 1);
  74.         }
  75.  
  76.         for (int i = 0; i < dt.Rows.Count; i++)
  77.         {
  78.             dt.Rows[i]["ID"] = (i + 1).ToString();
  79.         }
  80.  
  81.         LoadForm();
  82.  
  83.         GenerateResult();
  84.     }
  85.  
  86.     protected void btSave_Click(object sender, EventArgs e)
  87.     {
  88.         for (int i = 0; i < dt.Rows.Count; i++)
  89.         {
  90.             GridViewRow gr = GridView1.Rows[i];
  91.             DataRow dr = dt.Rows[i];
  92.             dr["First Name"] = ((TextBox)gr.FindControl("txtFirstName")).Text;
  93.             dr["Last Name"] = ((TextBox)gr.FindControl("txtLastName")).Text;
  94.             dr["Go To School"] = ((DropDownList)gr.FindControl("dropGoToSchool")).SelectedValue;
  95.             dr["School Name"] = ((TextBox)gr.FindControl("txtSchoolName")).Text;
  96.             dr["Grade"] = ((DropDownList)gr.FindControl("dropGrade")).SelectedValue;
  97.         }
  98.  
  99.         GenerateResult();
  100.  
  101.         Panel1.Visible = false;
  102.         Panel2.Visible = true;
  103.     }
  104. }
Dec 23 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Colm O'Hagan | last post by:
Hi there, I having a problem with a database I'm setting up, I would be delighted if someone out there could help. The database I'm setting up is a task register datebase, it will be used to...
10
by: MLH | last post by:
Would like to examine the value entered into a textbox on an A97 form during the BeforeUpdate event. The textbox may or may not have had an earlier entry in it prior to the latest value that is...
6
by: MLH | last post by:
Using A97. Want to examine 17-char VIN entered by user. VIN codes are alphanumeric and do not contain Oh's to prevent the confusion that could result if zeros were misread as O's or o's. So, if...
4
by: billa856 | last post by:
Hi, I want to know how can we set the value of Textbox = value of field in table when we select a value form combobx. example i have a table customer CID CNAME CSALARY 1 Billa ...
5
by: pratimapaudel | last post by:
I have one text box and submit button in one asp.net page. When users enter their email address in textbox and click submit button, i want to store that email address which comes from text box in sql...
7
by: Nick Ferreira | last post by:
How do you update value "Units available" on Table STOCK ON HAND from a value entered on a form for attribute "Units In" on table UNITS IN. I need to update the "Units available" as soon as control...
7
by: upcomingaman | last post by:
I am developing a add to cart page I'm using using DataList to display items and a small TextBox with default value "1" to show quantity. if user change this value to some other integer then the...
3
by: kirankumar214 | last post by:
Hai there, i have dynamically created windows from and added a dynamic textbox and button in it, user will enter some value in that textbox and clicks the button the form will be closed on the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.