Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic table 1

Status
Not open for further replies.

JDAEMS

Programmer
Aug 27, 2003
84
BE
Dear sir/madam,

I am writing an asp.net application in visual studio.net and i am stuck on something what I think shoulod be something very easy to do for more experienced users.

I have a simple table with the following fields:
Groupnumber
Groupname

What I want on my webpage is a table with all the groups in. If there are three groups, then I want to have three rows with the groupname in. If there are 7 groups, then I want to have a table with seven rows.

I do not want to make a table with hard-coded that many rows as I will get in trouble when this number is smaller than the number of groups.

So how can I make such a dynamic table?

I hope you can help me.

Thank you in advance.
Jelle
 
its very easy to do.ASP.Net provides many controls to provide this functionality like:DataGrid,DataList,Repeater.
as far as ur requirements 'Repeater' will the best choice.Do the following to implement the things.
1.in the aspx page include a repeater control:

<asp:Repeater Runat="server" ID="Groups">
<HeaderTemplate>
<table width="100%">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%# DataBinder.Eval(Container.DataItem, "Groupnumber") %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "Groupname") %>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>

2.in the codebehind file write the following

void Page_Load(Object sender, EventArgs e)
{

SqlConnection myConnection = new SqlConnection("user id=sa;initial catalog=pubs;data source=(local)\\VSdotNET;Connect Timeout=30");
SqlDataAdapter myCommand = new SqlDataAdapter("select * from groups", myConnection);

DataSet ds = new DataSet();
myCommand.Fill(ds, "Groups");

Groups.DataSource = ds.Tables["Groups"].DefaultView;
Groups.DataBind();
}


3.Make a table named-groups(groupnumber,groupname) on ur sqlserver.(if any other DB available then change the DB name in the connectionstring.

Compile the application and run it.



Rakhi
 
Thank you for replying to my message. This is indeed very handy information. I didn't know about these things as I am just a beginner in VB.Net and ASP.net.

Is it also possible in the repeater to have checkboxes before each groupname?

Let me explain, I want to give the users an overiew of all the product groups, but before the name of each product group there is a checkbox. And if the users want to delete groups, they have to check the checkbox and click the delete button.

So I don't think it will be a problem to add the checkboxes to the repeater, will it? But I'm already wondering how you can check which checkbox is checked and hwich are not checked. You will have to know this, so you can tell which are the groups to delete.

Is this also possible?

I'm sorry if I'm asking stupid questions, but I have to make these webpages and my knowledge is not very good concerning ASP.NET. I do know asp however, but they need me to program it in asp.net.

Thank you again very much for your help. I appreciate it a lot.
 
JDAEMS,
its better u use DataGrid instead of repeater for having checkbox in front of each group.
Take a data grid,make as many columns as u want.the column in which u want checkboxes, make it as template column,add a checkbox into it.
let me know if u want me to send the code to implement it.

Rakhi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top