473,700 Members | 2,353 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to show table dynamically related to value entered in textbox

1 New Member
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 1794
adriancs
122 New Member
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
3062
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 create work schedules for workers in a metal work shop, based on the tasks required to make a part and the tasks required to make the subcomponents of the part.
10
2301
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 now in the process of being entered. What's the best way to refer to the value just typed that is about to update the textbox?
6
4236
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 a user types a 17-char VIN into the textbox that has an Oh in it (lower or upper case) - I would like to change it to a zero during the BeforeUpdate code. So far, I've not been able to accomplish this. I can examine
4
10806
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 $5500
5
4159
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 server table. Sql database name is 'uprod'. Prod database has table named unsuscribe with column name email. Can anyone help me? I appreciate your answer. Thanks, Pinky
7
3795
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 is passed back after entering the "Units In" form. With "Units In" I need to Increase the value of "Units available" on table STOCK ON HAND. I also need to decrease the value in "Units Available" on table STOCK ON HAND when a value is entered on a...
7
11976
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 new value should be needed on next page I am finding it difficult that how to extract value from TextBox that i have used inside DataList -------HERE IS MY CODE------
3
1700
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 button click, now how to store the value entered in the dynamically created textbox on a dynamically created form, any help on this is greatly appreciated, thanks in advance
0
9218
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8975
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8929
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7816
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6564
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4408
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3095
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2395
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2031
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.