我正在开发一个项目,因为我有一个搜索选项并提交按钮。在提交时,如果有一些记录对应于选择,那么gridview会变得可见。但是我遇到的问题面对的是当页面加载第一次GridView不会出现,即使它有数据,但在调试时我发现数据被加载,但在第二次选择GridView变得可见。第一次加载页面的GridView可见性
下面的截图显示我的网页
以下是对提交按钮的代码单击
protected void btnsubmitclass_OnClick(object sender,EventArgs e)
{
if(drpfromclass.SelectedIndex>0 && drptoclass.SelectedIndex>0)
{
ds = objpromote.selectclasswise(ConfigurationManager.AppSettings["schoolcode"].ToString(),drpfromclass.SelectedItem.Value,drptoclass.SelectedItem.Value);
if(ds.Tables[0].Rows.Count>0)
{
foreach(GridViewRow gr in grdstudents.Rows)
{
grdstudents.Columns[0].Visible = true;
grdstudents.Columns[1].Visible = true;
grdstudents.Columns[2].Visible = false;
grdstudents.Columns[3].Visible = false;
grdstudents.Columns[4].Visible = true;
}
grdstudents.DataSource = ds;
grdstudents.DataBind();
grdstudents.Visible = true;
lblheading.Text = "Showing list of students moved from " + drpfromclass.SelectedItem.Text + " to " + drptoclass.SelectedItem.Text;
pnlgrd.Visible = true;
}
else
{
pnlgrd.Visible = false;
lblalerts.Text = "No record found";
lblalerts.Visible = true;
divalerts.Visible = true;
}
drpfromclass.ClearSelection();
drptoclass.ClearSelection();
}
else
{
lblalerts.Text = "Select fromclass and toclass";
lblalerts.Visible = true;
divalerts.Visible = true;
pnlgrd.Visible = false;
}
}
以下是ASPX代码
<asp:Panel ID="pnlgrd" runat="server" Visible="false">
<div style="width:700px;height:30px;" class="blueheadingdiv"><asp:Label ID="lblheading" runat="server" Text="Label" CssClass="lblheading"></asp:Label></div>
<div style="width:610px; height:500px;margin-top:10px; overflow-y:scroll;">
<asp:GridView ID="grdstudents" runat="server" Width="590" ForeColor="#333333" BorderColor="#6abb00" GridLines="None" AutoGenerateColumns="False" CellPadding="5">
<Columns>
<asp:BoundField HeaderText="Student Code" DataField="studentcode" Visible="false"/>
<asp:BoundField HeaderText="Student Name" DataField="studentname" Visible="false"/>
<asp:BoundField HeaderText="From Class" DataField="fromclass" Visible="false"/>
<asp:BoundField HeaderText="To Class" DataField="toclass" Visible="false"/>
<asp:BoundField HeaderText="Date" DataField="date" Visible="false"/>
</Columns>
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#4382EB" Font-Bold="True" ForeColor="White" CssClass="gridviewheader" HorizontalAlign="Left"/>
<PagerStyle BackColor="#4382EB" Font-Bold="True" ForeColor="White" CssClass="gridviewheader" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
</div>
</asp:Panel>
页面加载代码显示低于
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
filldrpclass();
}
}
您是否在页面加载上绑定了gridview ..? – Jameem
你可以发布你的Page_Load事件吗? –