I have a DevExpress gridview and I bind datasource
from code behind (c#) to it.
My action works properly, but when I use rowfilter
it doesn't.
I think my command argument, that sends information to my datasource
is wrong.
My id in row 1 is 1 and my id in row 13 should be 13 but after row the rowfilter
and click on button (row command) on row 13 , my id which sends to code behind (command argument) is 1 !
How can I get the ID from an row (GridView Devexpress)?
My gridview:
<dx:ASPxGridView ID="gv" runat="server" AutoGenerateColumns="False" OnRowCommand="gv_RowCommand" OnDataBinding="gv_DataBinding"
ClientInstanceName="gv" KeyFieldName="Id"
Width="100%">
<Columns>
<dx:GridViewDataTextColumn Caption="" CellStyle-HorizontalAlign="Center" VisibleIndex="0" Width="12%">
<DataItemTemplate>
<asp:LinkButton ID="btnconfirm" Text="Print" Width="70px" CssClass="btn btn-primary btn-small" ForeColor="#cc0000" CommandArgument='<%# Eval("Id") %>'
CommandName="print" runat="server"
OnClientClick="return confirm('Print?');">
</asp:LinkButton>
</DataItemTemplate>
<HeaderStyle HorizontalAlign="center" />
</dx:GridViewDataTextColumn>
</Columns>
<SettingsPager PageSize="80">
</SettingsPager>
<Settings ShowFilterRow="true" />
</dx:ASPxGridView>
My binding code:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
refreshGrid();
gv.DataBind();
}
}
protected void gv_DataBinding(object sender, EventArgs e)
{
refreshGrid();
}
protected void gv_RowCommand(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewRowCommandEventArgs e)
{
if (e.CommandArgs.CommandName == "print")
{
String _ID = e.CommandArgs.CommandArgument.ToString();
}
}
private void refreshGrid()
{
DataClasses1DataContext m = new DataClasses1DataContext();
var q = from p in m.TblUserElectronics.AsQueryable()
from w in m.ViewPersonCarRelations
where p.CID == w.CarId
select new
{
p.Id,
p.Enabled,
CodeTaxi = w.Code_Taxi
};
gv.DataSource = q;
}
Javascript Functions :
Modified Devexpress GridView: