您可以使用UpdateProgress
控件來實現此目的。當發生任何AJAX postback
時,您可以在UpdateProgess
容器內顯示任何內容。請看下面的例子:
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
Thread.Sleep(200);
tt.InnerText = DateTime.Now.ToShortTimeString();
grid.DataSource = new List<object>
{
new {Name = "Munim", Age = 2, Time = DateTime.Now.ToShortTimeString()},
new {Name = "Rashim", Age = 3, Time = DateTime.Now.ToShortTimeString()},
new {Name = "Robin", Age = 25, Time = DateTime.Now.ToShortTimeString()}
};
grid.DataBind();
}
</script>
<form id="form1" runat="server">
<asp:ScriptManager runat="server" ID="sm">
</asp:ScriptManager>
<div>
<asp:UpdatePanel runat="server" ID="UpdPnl1" UpdateMode="Conditional">
<ContentTemplate>
<asp:DataGrid runat="server" ID="grid"></asp:DataGrid>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="click" />
<div id="tt" runat="server">
</div>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="updQuoteProgress" runat="server" AssociatedUpdatePanelID="UpdPnl1"
DisplayAfter="0">
<ProgressTemplate>
Loading...</ProgressTemplate>
</asp:UpdateProgress>
</div>
</form>
使用表中你DataSet
protected void Button1_Click(object sender, EventArgs e)
{
//Thread.Sleep(1500);
string sqr = "select * from Pra_Region";
da = new SqlDataAdapter(sqr, con);
ds = new DataSet();
da.Fill(ds);
grdProduct.Visible = true;
grdProduct.DataSource = ds.Tables[0];
grdProduct.DataBind();
}
當我綁定數據到GridView控件它沒有顯示GridView的。我編寫的代碼將按鈕單擊事件中的datba綁定到gridview。它不顯示gridview。 –
@Suryasasidhar是否嘗試調用'dataGrid.DataBind()'?我已經更新了上面的代碼。請看看 –
你會顯示代碼 –