只是我试图从 devexpress gridview 中获取选定的行,但它对我来说从来没有用过,我尝试过客户端和自定义回调,并尝试过服务器端,但它没有用,花了 10 个小时搜索并尝试了我的每一个解决方案得到但对我没有任何帮助,有人可以给我一个提示,我错过了什么?,这是代码:
默认.aspx:
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script type="text/javascript">
</script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<div>
<dx:ASPxGridView ID="ASPxGridView1" ClientInstanceName="ASPxGridView1" KeyFieldName="ID" AutoGenerateColumns="False" runat="server">
<Columns>
<dx:GridViewCommandColumn ShowSelectCheckbox="True" VisibleIndex="0"
Caption="Select" Name="Select">
</dx:GridViewCommandColumn>
<dx:GridViewDataTextColumn Caption="ID" FieldName="pag_id_pk" Name="ID"
VisibleIndex="1">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn Caption="Name" FieldName="pag_name" Name="Name"
VisibleIndex="2">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn Caption="Title" FieldName="pag_title" Name="Title"
VisibleIndex="3">
</dx:GridViewDataTextColumn>
</Columns>
</dx:ASPxGridView>
<dx:ASPxButton ID="ASPxButton1" runat="server" AutoPostBack="False" Text="Get Values" UseSubmitBehavior="False" onclick="ASPxButton1_Click" />
</div>
</asp:Content>
默认.cs:
public partial class _Default : System.Web.UI.Page
{
DataTable table = null;
protected void Page_Init(object sender, EventArgs e)
{
if (!IsPostBack && !IsCallback)
{
string connectionString = ...
con.Open();
SqlDataReader rd;
SqlCommand cmd = new SqlCommand("SELECT * FROM [Pages]", con);
rd = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(rd);
ASPxGridView1.DataSource = dt;
Session["dt"] = (DataTable)dt;
ASPxGridView1.DataBind();
rd.Close();
con.Close();
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ASPxButton1_Click(object sender, EventArgs e)
{
List<object> indexes = new List<object>();
for (int i = 0; i < ASPxGridView1.VisibleRowCount; i++)
{
if (ASPxGridView1.Selection.IsRowSelected(i))
{
indexes.Add(ASPxGridView1.GetRowValues(i, ASPxGridView1.KeyFieldName));
}
}
foreach (var selectedKey in ASPxGridView1.GetSelectedFieldValues(ASPxGridView1.KeyFieldName))
{
if (!indexes.Contains(selectedKey))
ASPxGridView1.Selection.UnselectRowByKey(selectedKey);
}
}
提前致谢...
更新:当我使用“asp:SqlDataSource”时它工作正常。