【发布时间】:2015-08-05 05:59:22
【问题描述】:
如果没有数据,我想动态隐藏gridview的列。 有一列,即我想隐藏的附件,但不幸的是编码有问题,但我找不到它 以下是我的代码
<asp:GridView ID="GridView1" CssClass="attengrid" runat="server" Width="100%" AutoGenerateColumns="false"
ShowHeader="true" onrowdatabound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="EmpName" HeaderText="Emp.Name"></asp:BoundField>
<asp:BoundField DataField="DOB" HeaderText="DOB"></asp:BoundField>
<asp:BoundField DataField="Qualification" HeaderText="Designation"></asp:BoundField>
<asp:BoundField DataField="HomePlace" HeaderText="Home Town"></asp:BoundField>
<asp:BoundField DataField="DOJInGovrService" HeaderText="DOJ In Gov.Service"></asp:BoundField>
<asp:BoundField DataField="DOJInSamvarg" HeaderText="DOJ In Samvarg"></asp:BoundField>
<asp:BoundField DataField="DOJInCurrentOff" HeaderText="DOJ In Current Off."></asp:BoundField>
<asp:BoundField DataField="CurrentOfficePlace" HeaderText="Current Office"></asp:BoundField>
<asp:BoundField DataField="class" HeaderText="Category"></asp:BoundField>
<asp:BoundField DataField="Attachment" HeaderText="Attachment"></asp:BoundField>
</Columns>
</asp:GridView>
以下是.aspx.cs
protected void btnSearch_Click(object sender, EventArgs e)
{
dbAccess.execute("select ED.class,ED.CurrentOfficePlace,ED.DOB,ED.DOJInCurrentOff,ED.DOJInGovrService,ED.DOJInSamvarg,ED.EmpName,ED.HomePlace,ED.Qualification, ED.Attachment from tbl_EmplyeesBiodata ED where ED.CurrentOfficePlace='" + ddlCurrentPlacePosting.SelectedItem.Text + "'", DBAccess.SQLType.IS_QUERY);
DataTable dt = dbAccess.records1();
if (dt.Rows.Count > 0)
{
Label8.Text = dt.Rows.Count.ToString();
GridView1.DataSource = dt;
GridView1.DataBind();
lblmsg.Style.Add("display", "block");
lblmsg.Attributes.Add("class", "success");
lblmsg.InnerHtml = closediv + "Case Found";
tdnotice.Style.Add("display", "block");
}
else
{
lblmsg.Style.Add("display", "block");
lblmsg.Attributes.Add("class", "error");
lblmsg.InnerHtml = closediv + "No Case Found";
tdnotice.Style.Add("display", "none");
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string val = e.Row.Cells[9].ToString();
if (string.IsNullOrEmpty(val))
{
GridView1.Columns[9].Visible = false;
}
}
}
此代码不起作用,它仍在显示该列 请帮忙
【问题讨论】: