Devexpress Gridview Row command Error when Filtering Enabled
I am using devexpress 9.1.
I have devexpress gridview binded to datasource. have set a page size="20". Enabled Settings ShowFilterRow="true";
I have column with asp image button setting its command arguments to a value.
Below is the code
<dxwgv:ASPxGridView ID="ASPxGridView2" runat="server" DataSourceID="sds_addingredients"
AutoGenerateColumns="False" KeyFieldName="Ingredients_Id" ClientInstanceName="grid2">
<Settings ShowFilterRow="true" />
<SettingsPager PageSize="20"></SettingsPager>
<Columns>
<dxwgv:GridViewDataTextColumn Caption="S.No" VisibleIndex="0" >
<DataItemTemplate>
<%#Container.ItemIndex +1 %>
</DataItemTemplate>
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn VisibleIndex="1" Caption=" ">
<DataItemTemplate>
开发者_如何学JAVA <asp:ImageButton ID="btn_edit" runat="server" CommandArgument='<%# Eval("Ingredients_Id") %>' Height="15px"
ImageUrl="~/images/document_edit.png" ToolTip="Edit"
Width="15px" />
</DataItemTemplate>
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn VisibleIndex="1" FieldName="Ingredients_Id"
ReadOnly="True" Visible="False">
<EditFormSettings Visible="False" />
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn Caption="Ingredient" FieldName="Ingredients_Name" VisibleIndex="2" Settings-ShowFilterRowMenu="True" >
</dxwgv:GridViewDataTextColumn>
</Columns>
Below show server side code
protected void ASPxGridView2_RowCommand(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewRowCommandEventArgs e)
{ string id = e.CommandArgs.CommandArgument.ToString();//perform certain opertation based on the id}
The above method works properly but when i filter the result and click certain row, the Id received in the server end seems to be different not corresponding to what i clicked . i feel it gets the wrong row index... this happens only when i try filtering and perform row command click. Other wise it works properly. why is this.
Have you tried using they KeyValue property?
protected void ASPxGridView2_RowCommand(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewRowCommandEventArgs e)
{
int id = Convert.ToInt32(e.KeyValue);
//perform certain opertation based on the id
}
精彩评论