Answered by:
How can I display record from database using div html instead of datalist

Question
-
User-2074858223 posted
How can I display record from database using div html instead of datalist.Sunday, May 8, 2016 5:44 PM
Answers
-
User36583972 posted
Hi micah2012,
From your description, I think you can try the following method.
HTML:
<form id="form1" runat="server"> <div> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /> <br /> </div> <asp:Panel runat="server" ID="pnlUserdata"> </asp:Panel> </form>
ASPX.CS:
DataTable dt = new DataTable(); dt.Columns.Add("ID"); dt.Columns.Add("Name"); dt.Columns.Add("Enabled"); for (int i = 0; i < 2; i++) { for (int j = 0; j < 1; j++) { DataRow dr = dt.NewRow(); dr[0] = i.ToString(); dr[1] = i.ToString() + "-" + j.ToString(); dr[2] = Convert.ToBoolean(i % 2); dt.Rows.Add(dr); } } for(int i =0; i < dt.Rows.Count;i++) { HtmlGenericControl divcontrol = new HtmlGenericControl(); divcontrol.Attributes["class"] = "class1"; divcontrol.TagName = "div"; pnlUserdata.Controls.Add(divcontrol); Label question = new Label(); question.Text = dt.Rows[i][0].ToString() + "-" + dt.Rows[i][1].ToString() + "-" + dt.Rows[i][2].ToString(); divcontrol.Controls.Add(question); }
The following tutorial for your reference.
Display DataTable in HTML Table in ASP.Net using C# and VB.Net:
http://www.aspsnippets.com/Articles/Display-DataTable-in-HTML-Table-in-ASPNet-using-C-and-VBNet.aspx
Best Regards,
Yohann Lu
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, May 10, 2016 7:57 AM
All replies
-
User-1780421697 posted
You can get data from database for a class by several methods.
1: You can use ORM where you defined entities.
2: Entity can be populated with data when you get from database by using Enterprise Lib or ORM like Entity Framework.Sunday, May 8, 2016 6:10 PM -
User-2074858223 posted
Sorry there was an error in the question asked, I have updated the question. ThanksSunday, May 8, 2016 6:50 PM -
User-158764254 posted
you could use a ListView control or a Repeater control either of which give you full control over what markup gets mixed in with your data.
Sunday, May 8, 2016 8:21 PM -
User-2074858223 posted
I just want to use div htmlSunday, May 8, 2016 9:56 PM -
User-158764254 posted
1 record of data?
many records of data?
1 data column ?
many data columns?
i think you may need to elaborate just a bit so people can offer you more specific suggestions.
note that a Repeater can be used to output divs with your data as can the ListView
Monday, May 9, 2016 12:23 AM -
User-1636183269 posted
If you can provide more details, so we can give you specific code. You can create your <Table><tr><td>das</td></tr></table>
http://www.c-sharpcorner.com/UploadFile/736ca4/display-records-in-html-page-using-Asp-Net-web-api-2/
Monday, May 9, 2016 1:10 AM -
User-2074858223 posted
I want to display many data columns using div HTML, like example. <div> image <\div > <div> Label<\div>Monday, May 9, 2016 8:26 AM -
User36583972 posted
Hi micah2012,
From your description, I think you can try the following method.
HTML:
<form id="form1" runat="server"> <div> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /> <br /> </div> <asp:Panel runat="server" ID="pnlUserdata"> </asp:Panel> </form>
ASPX.CS:
DataTable dt = new DataTable(); dt.Columns.Add("ID"); dt.Columns.Add("Name"); dt.Columns.Add("Enabled"); for (int i = 0; i < 2; i++) { for (int j = 0; j < 1; j++) { DataRow dr = dt.NewRow(); dr[0] = i.ToString(); dr[1] = i.ToString() + "-" + j.ToString(); dr[2] = Convert.ToBoolean(i % 2); dt.Rows.Add(dr); } } for(int i =0; i < dt.Rows.Count;i++) { HtmlGenericControl divcontrol = new HtmlGenericControl(); divcontrol.Attributes["class"] = "class1"; divcontrol.TagName = "div"; pnlUserdata.Controls.Add(divcontrol); Label question = new Label(); question.Text = dt.Rows[i][0].ToString() + "-" + dt.Rows[i][1].ToString() + "-" + dt.Rows[i][2].ToString(); divcontrol.Controls.Add(question); }
The following tutorial for your reference.
Display DataTable in HTML Table in ASP.Net using C# and VB.Net:
http://www.aspsnippets.com/Articles/Display-DataTable-in-HTML-Table-in-ASPNet-using-C-and-VBNet.aspx
Best Regards,
Yohann Lu
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, May 10, 2016 7:57 AM