紧急求助:checkbox取不到gridview的值
//((Label)GridView1.Rows[i].Cells[7].FindControl("Label7")).Text;
{
StringBuilder s = new StringBuilder();
s.AppendLine("<table style='width:800px' border=1>");
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox ck = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("CheckBox1");
if (ck.Checked)
{
//GridView1.Columns
s.AppendLine("<tr>");
for (int j = 0; j < GridView1.Columns.Count; j++)
{
s.AppendFormat("<td>{0}</td>", GridView1.Rows[i].Cells[j].Text);//这个地方怎么用上面的格式来表示?
}
s.AppendLine("</tr>");
}
}
s.Append("</table>");
Export("application/ms-excel", "excel.xls", s.ToString());
--------------------编程问答--------------------
--------------------编程问答--------------------
for (int i = 0; i < GridView1.Rows.Count-1; i++)
从0开始到COUNT-1 --------------------编程问答-------------------- Columns 当前上下文中不存在名称“Columns”
--------------------编程问答-------------------- 一楼的 --------------------编程问答-------------------- ((Label)GridView1.Rows[i].Cells[j].FindControl("Label"+j)).Text; ???
--------------------编程问答--------------------
--------------------编程问答-------------------- StringBuilder s = new StringBuilder();
{
StringBuilder s = new StringBuilder();
s.AppendLine("<table style='width:800px' border=1>");
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox ck = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("CheckBox1");
//调试的时候,CK取到的是FASLE
if (ck.Checked)
{
//GridView1.Columns
s.AppendLine("<tr>");
for (int j = 0; j < GridView1.Columns.Count; j++)
{
s.AppendFormat("<td>{0}</td>", GridView1.Rows[i].Cells[j].Text);//这个地方怎么用上面的格式来表示?
}
s.AppendLine("</tr>");
}
}
s.Append("</table>");
Export("application/ms-excel", "excel.xls", s.ToString());
string id = "";
string[] ckb = null;
s.AppendLine("<table style='width:800px' border=1>");
for (int i = 0; i < GridView1.Rows.Count; i++)
{
id = Request.Form.Get("CheckBox1");
ckb = id.Split(new char[] { ',' });
for (int i = 0; i < ckb.Length; i++)
{
//你的操作
}
}
s.Append("</table>");
Export("application/ms-excel", "excel.xls", s.ToString());
--------------------编程问答--------------------
s.AppendLine("<table style='width:800px' border=1>");
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox ck = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("CheckBox1");
if (ck.Checked)
{
//GridView1.Columns
s.AppendLine(" <tr>");
for (int j = 0; j < GridView1.Columns.Count; j++)
{
s.AppendFormat("<td>{0} </td>", ((Label)GridView1.Rows[i].Cells[j].FindControl("Label")).Text);
// 提示出错:System.NullReferenceException: 未将对象引用设置到对象的实例。
}
s.AppendLine(" </tr>");
}
}
s.Append("</table>");
Export("application/ms-excel", "excel.xls", s.ToString());
补充:.NET技术 , ASP.NET