我是asp.net中的新手。在一个面板控件中创建了一个动态网格视图。当用户选择一个下拉列表值并单击一个按钮时,这个gridview与datatable绑定并正确显示值。但我想显示选择动态gridview只更改下拉列表。不需要单击按钮。当我尝试这样做时,它没有显示gridview.its绑定值,但它没有显示。
HTML:
<div id="divdgvUpdate" style="display: none; width: 100%; height: 300px; overflow: scroll">
<asp:panel id="pnlupdate" runat="server">
<asp:DropDownList ID="ddlProcess" runat="server" AutoPostBack="true" onselectedindexchanged="ddlProcess_SelectedIndexChanged" CssClass="select2-chosen"></asp:DropDownList>
</asp:panel>
</div>
C#代码:
public void dynamicgridview()
{
GridView grdv = new GridView();
grdv.AutoGenerateColumns = false;
DataSet ds = new DataSet();
DataTable dt = new DataTable();
BL.ESSBL bl = new BL.ESSBL();
ds = GetEssDetails();//getting datatable
if (ds != null &&ds.Tables.Count>0 && ds.Tables[0].Rows.Count > 0)
{
dt = ds.Tables[0];
grdv.RowDataBound += new GridViewRowEventHandler(grdv_RowDataBound);
grdv.DataSource = null;
grdv.DataBind();
grdv.Columns.Clear();
for (int i = 0; i < dt.Columns.Count; i++)
{
BoundField boundfield = new BoundField();
boundfield.DataField = dt.Columns[i].ColumnName.ToString();
boundfield.HeaderText = dt.Columns[i].ColumnName.ToString();
grdv.Columns.Add(boundfield);
}
TemplateField tmf = new TemplateField();
grdv.Columns.Add(tmf);
tmf = new TemplateField();
grdv.Columns.Add(tmf);
grdv.DataSource = dt;
grdv.DataBind();
grdv.Width = 600;
grdv.CellPadding = 10;
grdv.CellSpacing = 2;
grdv.Attributes["class"] = "Shorter";
pnlupdate.Controls.Add(grdv);
}
}
protected void btnGO_Click(object sender, EventArgs e)//its working
{
ddlprocessid = Convert.ToInt32(Session["ddlprocessid"]);
dynamicgridview();
}
protected void ddlProcess_SelectedIndexChanged(object sender, EventArgs e)//not working
{
dynamicgridview();
Clear();
}
按钮点击它正常工作。但是下拉选项改变了它不工作。我想刷新面板或什么?。请帮助我。