Thursday, 7 July 2011

Binding div in asp.net with c#

<div id="htmlDiv" runat="server"></div>


protected void Page_Load(object sender, EventArgs e)
{
DataSet ds = new DataSet();
sql sqlcon = new sql();//my business logic
ds = sqlcon.ExecuteDataSet("GetData");//fetched the data
if (ds.Tables[0].Rows.Count > 0)
{
string st = "<table border='0' cellspacing='0' cellpadding='0'>";
st += "<th align='center'>Table Header</th>";
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
st += "<tr><td><span>" + ds.Tables[0].Rows[i]["Sno"].ToString() + "</span></td>";
st += "<td><span>" + ds.Tables[0].Rows[i]["Sname"].ToString() + "</span></td></tr>";
}
}
st += "</table>";
htmlDiv.InnerHtml = st;
}

Tag: Usging Html Tags in asp.net

No comments:

Post a Comment

Parsing JSON w/ @ symbol in it

To read the json response like bellow @ concatenated with attribute                             '{ "@id": 1001, "@name...