更新我有一個GridView與下面的屬性Gridview1不會回發
AllowSorting="true"
AutoGenerateColumns="false"
BorderStyle="None"
CellPadding="3"
CssClass="inboundTbl"
EnableModelValidation="True"
PageSize="2"
OnPageIndexChanging="GridView1_PageIndexChanging"
OnRowDataBound="GridView1_RowDataBound"
OnSorting="GridView1_Sorting"
Width="100%"
>
和一些奇怪的原因,它不喜歡更新,當我試圖某人的排序教程。那麼,這次我正在嘗試一個過濾器教程,我對這個問題非常困惑。
這是有問題的templatefield。
<asp:TemplateField HeaderText="Current Terminal ID" SortExpression="VUCTID">
<HeaderTemplate>
Terminal:
<asp:DropDownList ID="ddlTerminal" runat="server"
AppendDataBoundItems="true"
AutoPostBack="true"
OnSelectedIndexChanged="TerminalChanged"
>
<asp:ListItem Text="ALL" Value="ALL"></asp:ListItem>
</asp:DropDownList>
</HeaderTemplate>
<ItemTemplate>
<%# Eval("VUCTID") %>
</ItemTemplate>
</asp:TemplateField>
我要求幫助,爲什麼它不會更新,他說,在GridView的動態填充,這會導致數據表返回空值。我不確定那是什麼意思,但自那以後我還沒有收到他的消息。我會發布函數進行過濾,以防出現問題。
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack){
ViewState["Filter"]="ALL";
BindGridView();
lastUpdated.Text = "Load: " + DateTime.Now;
}
}
protected void BindGridView()
{
string query = @"censored";
using (iDB2Connection conn = new iDB2Connection(connect))
{
using (iDB2Command cmd = new iDB2Command(query, conn))
{
conn.Open();
iDB2DataAdapter da = new iDB2DataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = ds.Tables[0];
GridView1.DataSource = ds;
//iDB2DataReader reader;
//reader = cmd.ExecuteReader();
//GridView1.DataSource = reader;
GridView1.DataBind();
GridView1.GridLines = GridLines.Horizontal;
DropDownList ddlTerminal = (DropDownList)GridView1.HeaderRow.FindControl("ddlTerminal");
this.BindTerminalList(ddlTerminal);
}
}
}
protected void TerminalChanged(object sender, EventArgs e)
{
DropDownList ddlTerminal = (DropDownList)sender;
ViewState["Filter"] = ddlTerminal.SelectedValue;
this.BindGridView();
}
private void BindTerminalList(DropDownList ddlTerminal)
{
string query = "censored";
using (iDB2Connection conn = new iDB2Connection(connect))
{
using (iDB2Command cmd = new iDB2Command(query, conn))
{
conn.Open();
iDB2DataAdapter da = new iDB2DataAdapter();
ddlTerminal.DataSource = cmd.ExecuteReader();
ddlTerminal.DataTextField = "VUCTID";
ddlTerminal.DataValueField = "VUCTID";
ddlTerminal.DataBind();
}
ddlTerminal.Items.FindByValue(ViewState["Filter"].ToString()).Selected = true;
}
}
編輯:啊,我很抱歉。通過更新我的意思是它不會過濾gridview。模板中的下拉框將從數據庫中填充,一旦點擊,gridview應該根據選定的下拉項目進行更新和過濾。但是當我點擊它時,頁面會加載,但gridview看起來不受影響。
你能說清楚你的意思是「不會更新」嗎?我沒有關注。你是否試圖更新數據庫中的數據,這不起作用?你是否試圖改變客戶端的某些東西,以迴應PostBack,這不起作用? – jadarnel27
如果你在TerminalChanged()中拋出一個斷點,它是否曾經打過它? –
@KevinDeVoe是的。 – Emwat