CheckComboBoxColumn in DevExpress GridView
I want to get CheckedList DropDown control, which is a开发者_如何学编程 basic DropDown with checkbox in front of each list item.
I found this demo from their official site but I want the same effect in a ASPxGridView column.
I didn't understand your question clearly. Do you want to use CheckComboBoxColumn
in ASPxGridview
Column ? If so, you can use it like this.
<dx:ASPxGridView ID="grid" ClientInstanceName="grid" runat="server"
.........................
<Columns>
.........................
<EditItemTemplate> // If your Gridview has Edit Property.
.........................
<dx:ASPxListBox ...
If that didn't what you want, please let me know.
NOTE: Did you look ASPxGridLookup
control ? GridLookup - Multiple Selection
EDIT1: Check the following code. How to implement a CheckComboBox editor in the ASPxGridView
.ASPX
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register
Assembly="DevExpress.Web.ASPxGridView.v9.3, Version=9.3.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dx" %>
<%@ Register
Assembly="DevExpress.Web.ASPxEditors.v9.3, Version=9.3.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>GridCheckComboBox Emulation</title>
<script type="text/javascript">
var textSeparator = ",";
function OnGridSelectionChanged(Grid, args, checkComboBox) {
UpdateText(Grid, checkComboBox);
}
var _checkComboBox;
function UpdateText(checkGrid, checkComboBox) {
_checkComboBox = checkComboBox;
checkGrid.GetSelectedFieldValues('CategoryID;CategoryName', OnGetSelectedFieldValues);
}
function OnGetSelectedFieldValues(items) {
var texts = [];
for (var i = 0; i < items.length; i++)
texts.push(items[i][0]);
texts.join(textSeparator);
_checkComboBox.SetText(texts);
}
function SynchronizeGridValues(dropDown, args, checkGrid) {
var values = dropDown.GetText().split(textSeparator);
checkGrid.UnselectAllRowsOnPage();
checkGrid.SelectRowsByKey(values);
//UpdateText(checkGrid, dropDown); // for remove non-existing texts
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<dx:ASPxGridView ID="grid1" runat="server" AutoGenerateColumns="False" DataSourceID="AccessDataSource1">
<Columns>
<dx:GridViewDataTextColumn FieldName="CategoryID" ReadOnly="True" VisibleIndex="0">
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn Caption="test" VisibleIndex="1">
<DataItemTemplate>
<dx:ASPxGridView ID="grid2" runat="server" AutoGenerateColumns="False"
DataSourceID="AccessDataSource1">
<Columns>
<dx:GridViewDataTextColumn FieldName="CategoryID" ReadOnly="True"
VisibleIndex="0">
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn Caption="test" VisibleIndex="1">
<DataItemTemplate>
<dx:ASPxDropDownEdit ID="ddE" runat="server" OnInit="ddE_Init">
<DropDownWindowTemplate>
<dx:ASPxGridView ID="grid" runat="server"
AutoGenerateColumns="False" KeyFieldName="CategoryID"
DataSourceID="AccessDataSource1"
SettingsBehavior-AllowMultiSelection="True"
OnInit="grid_Init">
<Columns>
<dx:GridViewCommandColumn ShowSelectCheckbox="True"
VisibleIndex="0">
</dx:GridViewCommandColumn>
<dx:GridViewDataTextColumn FieldName="CategoryID"
VisibleIndex="1">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="CategoryName"
VisibleIndex="2">
</dx:GridViewDataTextColumn>
</Columns>
<SettingsPager Mode="ShowAllRecords" />
</dx:ASPxGridView>
<table style="width: 100%"><tr><td align="right">
<dx:ASPxButton ID="btn" runat="server" Text="close"
AutoPostBack="false" OnInit="btn_Init">
</dx:ASPxButton>
</td></tr></table>
</DropDownWindowTemplate>
</dx:ASPxDropDownEdit>
</DataItemTemplate>
</dx:GridViewDataTextColumn>
</Columns>
<SettingsPager Mode="ShowAllRecords" />
</dx:ASPxGridView>
</DataItemTemplate>
</dx:GridViewDataTextColumn>
</Columns>
<SettingsPager Mode="ShowAllRecords" />
</dx:ASPxGridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/nwind.mdb"
SelectCommand="SELECT [CategoryID], [CategoryName] FROM [Categories]"></asp:AccessDataSource>
</div>
</form>
</body>
</html>
.CS
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DevExpress.Web.ASPxEditors;
using DevExpress.Web.ASPxGridView;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ddE_Init(object sender, EventArgs e)
{
ASPxDropDownEdit dropdownedit = sender as ASPxDropDownEdit;
ASPxGridView grid = dropdownedit.NamingContainer.NamingContainer as ASPxGridView;
string key = grid.UniqueID;
string visibleIndex = (dropdownedit.NamingContainer as GridViewDataItemTemplateContainer).VisibleIndex +
key;
dropdownedit.ClientInstanceName = "dde" + visibleIndex;
dropdownedit.ClientSideEvents.DropDown =
String.Format("function(s,e) {{ SynchronizeGridValues(s, e, grid{0});}}", visibleIndex);
dropdownedit.ClientSideEvents.TextChanged =
String.Format("function(s,e) {{SynchronizeGridValues(s, e, grid{0});}}", visibleIndex);
}
protected void btn_Init(object sender, EventArgs e)
{
ASPxButton button = sender as ASPxButton;
ASPxGridView grid = button.NamingContainer.NamingContainer.NamingContainer.NamingContainer.NamingContainer
as ASPxGridView;
string key = grid.UniqueID;
string visibleIndex = (button.NamingContainer.NamingContainer.NamingContainer.NamingContainer as
GridViewDataItemTemplateContainer).VisibleIndex + key;
button.ClientSideEvents.Click = String.Format("function(s, e){{dde{0}.HideDropDown();}}", visibleIndex);
}
protected void grid_Init(object sender, EventArgs e)
{
ASPxGridView curGrid = sender as ASPxGridView;
ASPxGridView grid = curGrid.NamingContainer.NamingContainer.NamingContainer.NamingContainer.NamingContainer
as ASPxGridView;
string key = grid.UniqueID;
string visibleIndex = (curGrid.NamingContainer.NamingContainer.NamingContainer.NamingContainer as
GridViewDataItemTemplateContainer).VisibleIndex + key;
curGrid.ClientInstanceName = "grid" + visibleIndex;
curGrid.ClientSideEvents.SelectionChanged =
String.Format("function(s,e) {{ OnGridSelectionChanged(s, e, dde{0});}}", visibleIndex);
}
}
精彩评论