我有一个DevExpress gridview,我将datasource
从代码(c#)绑定到它。
我的操作正常,但是当我使用rowfilter
时,它没有。
我认为我的命令参数向我的datasource
发送信息是错误的。
我在行1中的id是1,我在行13中的id应该是13但是在行rowfilter
之后并且在行13上单击按钮(行命令),我的id发送到代码后面(命令参数) )是1!
如何从行中获取ID(GridView Devexpress)?
我的网格视图:
<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>
我的绑定代码:
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;
}
答案 0 :(得分:0)
Javascript功能:
function gv_CustomButton_Click(s, e) {
switch (e.buttonID) {
case "cmdPrint":
if (confirm("Print?")) {
s.GetRowValues(e.visibleIndex, 'ID', PrintCommand);
}
}
}
function PrintCommand(values) {
var ID = values; //this will give u actual ID.
//put your actions here
}
修改了Devexpress GridView:
<dx:ASPxGridView ID="gv" runat="server" AutoGenerateColumns="False" OnRowCommand="gv_RowCommand" OnDataBinding="gv_DataBinding"
ClientInstanceName="gv" KeyFieldName="Id" Width="100%">
<ClientSideEvents CustomButtonClick="gv_CustomButton_Click" />
<Columns>
<dx:GridViewCommandColumn VisibleIndex="0" ButtonType="Image" Width="12%" Caption="Actions" CellStyle-VerticalAlign="Top" Visible="false" ShowInCustomizationForm="true">
<CustomButtons>
<dx:GridViewCommandColumnCustomButton ID="cmdPrint" Image-ToolTip="Print" CssClass="btn btn-primary btn-small">
</dx:GridViewCommandColumnCustomButton>
</CustomButtons>
<HeaderStyle HorizontalAlign="center" />
</dx:GridViewCommandColumn>
</Columns>
<SettingsPager PageSize="80">
</SettingsPager>
<Settings ShowFilterRow="true" />
</dx:ASPxGridView>