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

I have one textboxes. I want to fetch the record from table and display in dynamic textboxes in column wise. for example i have sixteen records then i need to display 16 columns in one row.

How to do that...

my code is below

ASPX page
-----------
XML
<tr>
     <td class="Content">Sno</td>
     <td class="Content">Name</td>
     <td>
                  <asp:TextBox runat="server" id="txtDesign">
     </td>
</tr>
<tr>
		              <td align="left" colspan="18" class="Content">Engineers</td>
	            </tr>
                <tr>
		                <td align="left" colspan="18">Designers</td>
	            </tr>


ASPX.VB Code
------------
VB
StrQry = ""
        StrQry = "Select Designation,DesigCode,Priority,Priority2,ProfRoleCode,ProfRole,DeptCode from Designation where DeptCode='" & Session("Dept") & "' order by Priority2"
        Cmd.Connection = Conn
        Cmd.CommandText = StrQry
        Rdr = Cmd.ExecuteReader
        Dim recCount As Integer = 0
        'recCount = Rdr.HasRows
        If Rdr.HasRows Then
            While Rdr.Read
                txtDesign.Text = Rdr("Designation")
                recCount = recCount + 1
            End While
            recCount = recCount ' To Count the Number of Records
        End If
        Rdr.Close()
        Conn.Close()


How to do that
Posted
Updated 6-Jul-11 1:05am
v2
Comments
Sergey Alexandrovich Kryukov 6-Jul-11 11:49am    
What is non-dynamic text box?
--SA

Try this...

for (int i = 0; i < RDL.Count; i++)
{

	TableRow tr = new TableRow();
        TableCell td = new TableCell();
        TextBox textBox = new TextBox();
        td = new TableCell();
        td.Width = Unit.Pixel(145);
        textBox = new TextBox();
        textBox.Text ="From DB";
        td.Controls.Add(textBox );
	if(i=RDL.Count-1)
	{
		tr.Controls.Add(td);
	}

}
 
Share this answer
 
v2
Comments
gani7787 6-Jul-11 7:19am    
Hi,
What is lbl..?
Deepthi Aravind 6-Jul-11 7:33am    
Sorry...pls check the solution now...
Dear,
If You Have A Datatable, then DataGrid Is The Best Way for This.
 
Share this answer
 
Hi,
There is many solution on adding TextBox dynamically, but that require some additional workaround as .Net only recognize controls available on control collection , so you have to add each dynamic control to its control collection to use those from server side. Soin my opinion best way is use GridView and use TemplateField. This way you can dynamically add TextBox and able to use them from server side.
 
Share this answer
 
 
Share this answer
 

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



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