我在Web应用程序中拥有这种结构,根据用户的选择,Table_1或Table_2具有可见性;他们永远都不可见。
<table>
<tr><td>
<table id="Table_1" runat="server" visible="false">
<tr><td>...</td></tr>
<tr><td>
<asp:GridView>
<asp:Linkbutton>
<asp:FormView>
</td></tr>
</table>
<table id="Table_2" runat="server" visible="false">
<tr><td>...</td></tr>
<tr><td>
<asp:GridView>
</td></tr>
</table>
</td></tr>
</table>
奇怪的是,只有当表2的孔代码块位于顶部时才有效。如果我将它们切换回代码描述的方式,table_2永远不会出现。我不再添加任何东西了。只需在代码中切换两个表,一旦结果正确,而在另一种情况下则不是。
这与此有什么关系?
控制可见性的代码:
protected void GridView01_OnSelectedIndexChanged(object sender, EventArgs e)
{
FilterDDLResponsable.SelectedIndex = -1;
GridView3.Visible = true;
GridView3.EditIndex = -1;
Table_1.Visible = true;
Table_2.Visible = false;
GridView3.DataBind();
ButtonEditMode.Visible = false;
ButtonSendHWReminderSeries.Visible = false;
if (AdminUser.Text == "1")
{
AddButton.Visible = true;
}
LabelAuditID.Text = Convert.ToString(GridView01.SelectedValue);
if(ActivateTabletView.Checked == true)
{
GridView01.Columns[12].Visible = true;
GridView01.Columns[13].Visible = true;
GridView01.Columns[14].Visible = true;
}
else
{
GridView01.Columns[12].Visible = false;
GridView01.Columns[13].Visible = false;
GridView01.Columns[14].Visible = false;
}
FillGrid();
}
和Grid的行LinkButton onClick方法:
protected void OpenAudit(object sender, EventArgs e)
{
LinkButton btn = (LinkButton)(sender);
string AuditID = btn.CommandArgument;
Table_1.Visible = false;
Table_2.Visible = true;
LabelAuditID.Text = AuditID;
foreach (GridViewRow gvRow in GridView01.Rows)
{
if ((int)GridView01.DataKeys[gvRow.DataItemIndex].Value == Convert.ToUInt32(AuditID))
{
GridView01.SelectedIndex = gvRow.DataItemIndex;
break;
}
}
FillQuestionsGrid();
}