我正在从下拉列表中选择值来过滤gridview。问题是,当我选择任何值时,它会给我正确的结果,但是当我选择默认值意味着Select the value
时,gridview仍会将错误视为No Records Found
。
我尝试为此实现更新面板,以便可以通过它进行处理。但我面临如下错误:
无法在关联控件'grdCSRPageData'上找到名为'Click'的事件,因为UpdatePanel的“updgridPage”中的触发器。
请在更新面板中查看我的代码: -
<asp:UpdatePanel ID="updgridPage" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="grdCSRPageData" runat="server" Width="100%" border="1" Style="border: 1px solid #E5E5E5;" CellPadding="3"
AutoGenerateColumns="False" OnDataBound="grdCSRPageData_DataBound" AllowPaging="true" CssClass="hoverTable" EmptyDataText="No Records Found"
OnPageIndexChanging="grdCSRPageData_PageIndexChanging" DataKeyNames="Id" OnRowDeleting="grdCSRPageData_RowDeleting"
PageSize="5" ShowFooter="true" OnRowEditing="grdCSRPageData_RowEditing" OnRowUpdating="grdCSRPageData_RowUpdating"
OnRowCancelingEdit="grdCSRPageData_RowCancelingEdit">
<AlternatingRowStyle CssClass="k-alt" BackColor="#f5f5f5" />
<Columns>
<asp:TemplateField HeaderText="Select" HeaderStyle-Width="5%" HeaderStyle-CssClass="k-grid td">
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" AutoPostBack="false" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="page_title" HeaderText="Page Title" ItemStyle-Width="30" HeaderStyle-CssClass="k-grid td" />
<asp:BoundField DataField="page_description" HeaderText="Page Description" ItemStyle-Width="30" HeaderStyle-CssClass="k-grid td" />
<asp:BoundField DataField="meta_title" HeaderText="Meta Title" ItemStyle-Width="30" HeaderStyle-CssClass="k-grid td" />
<asp:BoundField DataField="meta_keywords" HeaderText="Meta Keywords" ItemStyle-Width="30" HeaderStyle-CssClass="k-grid td" />
<asp:BoundField DataField="meta_description" HeaderText="Meta Description" ItemStyle-Width="30" HeaderStyle-CssClass="k-grid td" />
<asp:BoundField DataField="Active" HeaderText="Active" ItemStyle-Width="30" HeaderStyle-CssClass="k-grid td" />
<asp:TemplateField HeaderText="Action" HeaderStyle-Width="15%" HeaderStyle-CssClass="k-grid td">
<ItemTemplate>
<asp:ImageButton ID="btnDelete" AlternateText="Delete" ImageUrl="~/images/delete.png" runat="server" Width="15" Height="15" CommandName="Delete" CommandArgument='<%# Eval("Id") %>' CausesValidation="false" OnClientClick="return confirm('Are you sure you want to delete this record?')" />
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ButtonType="Image" ItemStyle-Width="15" EditImageUrl="~/images/edit.png" ShowEditButton="True" ControlStyle-Width="15" ControlStyle-Height="15" CancelImageUrl="~/images/close.png" UpdateImageUrl="~/images/update.png">
<ControlStyle Height="20px" Width="20px"></ControlStyle>
</asp:CommandField>
</Columns>
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="grdCSRPageData" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
让我知道我必须做出哪些改变。
网格视图的过滤代码: -
<asp:DropDownList ID="ddlPagesNgo" runat="server" CssClass="selectpicker form-control-drp wd" Style="width: 100%" AutoPostBack="true" OnSelectedIndexChanged="ddlPagesNgo_SelectedIndexChanged"></asp:DropDownList>
SelectedIndexChangedCode: -
protected void ddlPagesNgo_SelectedIndexChanged(object sender, EventArgs e)
{
BindGridView(ddlPagesNgo.SelectedValue);
}
BindGridView代码: -
public void BindGridView(string NgoId)
{
string strQuery = "select Id,page_title,page_description,meta_title,meta_keywords,meta_description,Active from tbl_Pages WHERE NgoId=" + NgoId + " ORDER By Id DESC";
SqlCommand cmd = new SqlCommand(strQuery);
DataTable dt = GetData(cmd);
grdCSRPageData.DataSource = dt;
grdCSRPageData.DataBind();
}
如果您还有其他需要,请告诉我
答案 0 :(得分:1)
使用此代码。你的错误是单击EventName错误
<Triggers>
<asp:AsyncPostBackTrigger ControlID="grdCSRPageData" EventName="PageIndexChanging" />
</Triggers>
答案 1 :(得分:0)
通过将if else条件
完成 public void BindGridView(string NgoId)
{
string strQuery = null;
if (NgoId != "0")
strQuery = "select Id,page_title,page_description,meta_title,meta_keywords,meta_description,Active from tbl_Pages WHERE NgoId=" + NgoId + " ORDER By Id DESC";
else
strQuery = "select Id,page_title,page_description,meta_title,meta_keywords,meta_description,Active from tbl_Pages ORDER By Id DESC";
SqlCommand cmd = new SqlCommand(strQuery);
DataTable dt = GetData(cmd);
grdCSRPageData.DataSource = dt;
grdCSRPageData.DataBind();
}