Merhaba arkadaslar bu makalemizde stringbuilder metodunu kullanarak dinamik olarak bir html tablo olusturacagiz. Ilk olarak;
using System.Text;
sayfamiza ekleyelim.
Sekil 1
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
sb.Append("<table border='1' cellpadding='1' cellspacing='0'>");
sb.Append("<tr>");
sb.Append("<td style='font-family:Tahoma; background-color:orangered; color: snow'>");
sb.Append("Sira No");
sb.AppendLine();
sb.Append("</td>");
sb.Append("<td style='font-family:Tahoma; background-color:orangered; color: snow'>");
sb.Append("<center>");
sb.Append("Ad");
sb.Append("</center>");
sb.AppendLine();
sb.Append("</td>");
sb.Append("<td style='font-family:Tahoma; background-color:orangered; color: snow'>");
sb.Append("Soyad");
sb.AppendLine();
sb.Append("</td>");
sb.Append("</tr>");
sb.Append("<tr>");
sb.Append("<td >");
sb.Append("1");
sb.AppendLine();
sb.Append("</td>");
sb.Append("<td>");
sb.Append("Bahadir");
sb.AppendLine();
sb.Append("</td>");
sb.Append("<td>");
sb.Append("Sahin");
sb.AppendLine();
sb.Append("</td>");
sb.Append("</tr>");
sb.Append("<tr>");
sb.Append("<td>");
sb.Append("2");
sb.AppendLine();
sb.Append("</td>");
sb.Append("<td>");
sb.Append("Mesut");
sb.AppendLine();
sb.Append("</td>");
sb.Append("<td>");
sb.Append("Alp");
sb.AppendLine();
sb.Append("</td>");
sb.Append("</tr>");
sb.Append("</table>");
Label1.Text = sb.ToString();
}
}
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Font-Names="Tahoma" Font-Size="X-Large" OnClick="Button1_Click" Text="Olustur" Width="156px" />
<br />
<br />
<br />
<asp:Label ID="Label1" runat="server" Font-Names="Tahoma" Font-Size="X-Large" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
Bir makalenin daha sonuna geldik. Bir sonraki makalede görüsmek üzere. Bahadir SAHIN
0 comments:
Yorum Gönder