我有这个devexpress gridview:
<dxwgv:ASPxGridView ID="ASPxGridView1" runat="server" DataSourceID="userDS" AutoGenerateColumns="False" Width="100%" KeyFieldName="contractId" >
<Styles>
<Header ImageSpacing="10px" SortingImageSpacing="10px">
</Header>
</Styles>
<SettingsEditing Mode="EditForm" />
<SettingsPager PageSize="39" ShowDefaultImages="False">
<AllButton Text="All">
</AllButton>
<NextPageButton Text="Next >">
</NextPageButton>
<PrevPageButton Text="< Prev">
</PrevPageButton>
</SettingsPager>
<Settings ShowFilterRow="True" ShowFilterRowMenu="true" />
<Columns>
<dxwgv:GridViewCommandColumn VisibleIndex="0" Width="55px">
<EditButton Visible="True">
</EditButton>
<DeleteButton Visible="False">
</DeleteButton>
<HeaderTemplate>
</HeaderTemplate>
</dxwgv:GridViewCommandColumn>
<dxwgv:GridViewDataTextColumn FieldName="contractId" ReadOnly="True" Visible="false"
VisibleIndex="1">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn FieldName="usergroupId" Caption="adult usergroupId" ReadOnly="true" VisibleIndex="2">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn FieldName="adultCode" Caption="educ. reg. code" VisibleIndex="3" ReadOnly="True" Visible="true">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn FieldName="accessLevel" VisibleIndex="3" ReadOnly="True" Visible="true">
<Settings AutoFilterCondition="Like" />
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn Settings-AllowAutoFilter="True" FieldName="adultId" ReadOnly="True" Caption="adult userId" Visible="true"
VisibleIndex="9">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewCommandColumn ShowClearFilterButton="true" ShowApplyFilterButton="true" VisibleIndex="1" />
</Columns>
</dxwgv:ASPxGridView>
<dxexport:ASPxGridViewExporter ID="gridExport" runat="server" GridViewID="ASPxGridView1"></dxexport:ASPxGridViewExporter>
<asp:SqlDataSource ID="userDS" runat="server"
ConnectionString="<%$ ConnectionStrings:connstring %>"
SelectCommand="GetAllUserAdultChildGroup"
OnDeleting="deleting" OnUpdating="updating">
</asp:SqlDataSource>
后端代码:
protected void Page_Load(object sender, EventArgs e)
{
//change the db cx string for the SqlDataSource to more robust code
string connString = ConfigurationManager.ConnectionStrings["connstring"].ConnectionString;
userDS.ConnectionString = connString;
userDS.UpdateParameters.Add("modified", TypeCode.DateTime, DateTime.Now.ToString());
}
protected void userDS_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
}
protected void deleting(object sender, SqlDataSourceCommandEventArgs e)
{
string s = userDS.DeleteCommand;
}
protected void updating(object sender, SqlDataSourceCommandEventArgs e)
{
string s = userDS.UpdateCommand;
}
但是当我尝试过滤时:https://i.gyazo.com/16c57c6c4cba47897f08402c143ccaf1.gif
什么都没发生,没有回发,没有。
你知道我是否遗漏了什么?
谢谢,Laziale
答案 0 :(得分:0)
从给定的代码看,您的gridview似乎在运行时使用参数化存储过程进行绑定。
但是,随着页面生命周期的变化,gridview不会缓存实际数据,因此您需要为每次请求或往返服务器提供数据。
请尝试以下这些替代方法来绑定您的gridview数据:
// use initialization method to bind data
protected void Page_Init(object sender, EventArgs e)
{
ASPxGridView1.DataSource = userDS;
ASPxGridView1.DataBind();
}
// use load method to bind data
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ASPxGridView1.DataBind();
}
}
// or place it on data binding method...
protected void ASPxGridView1_DataBinding(object sender, EventArgs e)
{
ASPxGridView1.DataSource = userDS;
}
请注意,ASPXGridView默认情况下不会在ViewState
中存储数据源信息,因为与纯网格服务器控件相比,客户端的ViewState
存在性能问题,因此每个页面请求都需要要绑定的有效数据源。
参考:https://www.devexpress.com/Support/Center/Question/Details/K18183