Programmatically get data from GridView using C# in ASP.NET

Kundnani.Rt
Posted by Kundnani.Rt under C# category on | Points: 40 | Views : 2658
        protected void Page_Load(object sender, EventArgs e)
{
StringBuilder strB = new StringBuilder();

strB.Append("<table border=1>");

for (int k = 0; k< dg.Rows.Count;k++)
{
strB.AppendLine("<tr>");
if (k== 0)
{
for (int j = 0; j < dg.Columns.Count; j++)
{
strB.AppendLine("<td align='center' valign='middle'>" +
dg.Columns[j].ToString() + "</td>"); //Here i'm getting Header text value instead of cell value
}
}
else
{
for (int j = 0; j < dg.Columns.Count; j++)
{
strB.AppendLine("<td align='center' valign='middle'>" + dg.Rows[i].Cells[j].Text
+ "</td>");
}
}
strB.AppendLine("</tr>");

}


strB.Append("</table>");
this.Page.Form.InnerHtml=strB.ToString();
}

Comments or Responses

Posted by: T.Saravanan on: 1/20/2013 Level:Silver | Status: [Member] [MVP] | Points: 10
Hi,

Kindly assign other variable in for loop instead of "i". Becasue in DNF site Square brace of 'i' is consider as italic.
Posted by: Kundnani.Rt on: 1/20/2013 Level:Starter | Status: [Member] | Points: 10
Thanks Saravanan for your valuable notification.

I have made changes appropriately.

Login to post response