GridView 中模板列莫名其妙消失
问题描述:Gridvie控件有一个固定的模板列,其它列都是动态添加的,包括ButtonField列.当我加载数据的时候,一切正常,但是当点击GridView中翻页后,模板列消失了,模板列的表头还在,就是内容消失了.其它列都没有问题.
代码如下:
<asp:GridView ID="GvSelectResult" PageSize="20" runat="server" AllowPaging="True" Width="1500"
BackColor="White" BorderColor="#A6CBEF" BorderStyle="Solid" BorderWidth="1px"
OnPageIndexChanging="GvSelectResult_PageIndexChanging" AutoGenerateColumns="False" OnRowCommand="GvSelectResult_RowCommand" OnRowDataBound="GvSelectResult_RowDataBound" OnRowCreated="GvSelectResult_RowCreated">
<Columns>
<asp:TemplateField HeaderText="<input id='Checkbox1' type='checkbox' onclick='selectAll(this)' />" >
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
public void addButtonField(string headText, string text, string cmdName)
{
ButtonField bf = new ButtonField();
bf.HeaderText = headText;
bf.Text = text;
bf.CommandName = cmdName;
GvSelectResult.Columns.Insert(0,bf);
}
public void addHyperLinkField(string headText, string text,
string[] DataNavigateUrlFields, string DataNavigateUrlFormatString, string Target)
{
HyperLinkField hlf = new HyperLinkField();
hlf.HeaderText = headText;
hlf.Text = text;
hlf.Target = Target;
hlf.DataNavigateUrlFields = DataNavigateUrlFields;
hlf.DataNavigateUrlFormatString = DataNavigateUrlFormatString;
GvSelectResult.Columns.Insert(0,hlf);
}
protected void Page_Init(object sender, EventArgs e)
{
DataSet reportKey, GvDataSet;
reportKey = new DataSet();
GvDataSet = new DataSet();
if (!String.IsNullOrEmpty(bbid))
{
reportKey = DbOperateClass.DbOperate.GetDataSet("select tablename,zdm,zwhy from zdybb where bbid='"
+ bbid + "' and yxbz='1' order by zdxssx");
string tableName;
DataTableReader dtr = new DataTableReader(reportKey.Tables[0]);
DataTableReader dtr1 = new DataTableReader(reportKey.Tables[0]);
DataTableReader dtr2 = new DataTableReader(reportKey.Tables[0]);
StringBuilder sb = new StringBuilder("select ");
try
{
dtr1.Read();
tableName = dtr1.GetString(0);
while (dtr.Read())
{
sb.Append(dtr.GetString(1));
sb.Append(",");
}
}
finally
{
dtr1.Close();
dtr.Close();
}
sb.Length = sb.Length - 1;
sb.Append(" from ");
sb.Append(tableName);
ViewState["selectSql"] = sb.ToString();//保存查询命令
GvDataSet = DbOperateClass.DbOperate.GetDataSet(sb