首先我尝试在pageload上显示gridview所以girdveiw成功显示现在我尝试显示当点击按钮我尝试下面的代码但网格不可见
代码
DataTable dt = new DataTable();
public DataTable info(string id)
try
{
Entities2 wr = new Entities2();
List<spv_Result> sv = wr.spvec(id).ToList();
dt.Columns.Add("RowNumber", typeof(int));
foreach (var c in sv)
{
dt.Rows.Add(c.RowNumber);
}
return dt;
}
catch (Exception ex)
{
throw new Exception();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
info(id);
GridView1.DataSource = dt;
GridView1.DataBind();
}
dt中有数据,但gridview不显示
<asp:GridView ID="GridView1" runat="server" class="display nowrap"
Width="100%" CellPadding="0"
Font-Names="Verdana" BackColor ="White" BorderColor="#CCCCCC" BorderStyle="None"
BorderWidth="1px" Font-Size="9pt">
<FooterStyle BackColor="White" ForeColor="#000066" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#007DBB" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#00547E" />
任何解决方案?
答案 0 :(得分:0)
我认为“dt”在按钮点击事件的下一行没有任何价值。
/tmp
试试这个:
cd /tmp
wget http://...
这里,“info”方法直接返回datatable,然后将值分配给Gridview。