问题描述
- GridViewDataDropDownEditColumn嵌套ASPxComboBox
-
情景:
使用GridView自带的AddNewRow()添加一条记录到表A(listA是流水号,listB来自B表),弹出添加窗口中有一个字段的值时从另外一个表B动态选择的,效果如图1。
为此在Page1.aspx中写了如下的代码前台:
<div id="divOperation" class="bulk-actions align-right"> <dx:ASPxButton ID="btnAdd" runat="server" AutoPostBack="False" ClientIDMode="AutoID" Text=" 添 加 " UseSubmitBehavior="False" ClientInstanceName="btnAdd" CausesValidation="False" CssClass="buttonAqua" Theme="Aqua"> <ClientSideEvents Click="function(s, e) { gvList.AddNewRow(); }" /> </dx:ASPxButton> </div> <div class="main-grid"> <dx:ASPxGridView ID="gvList" runat="server" AutoGenerateColumns="False" EnableCallBacks="True" ClientIDMode="AutoID" OnInitNewRow="gvList_InitNewRow" OnCellEditorInitialize="gvList_CellEditorInitialize" OnCustomErrorText="gvList_CustomErrorText" OnRowInserting="gvList_RowInserting" ClientInstanceName="gvList" Width="99.9%" KeyFieldName="ydyxlsh" Theme="Aqua"> <Columns> <dx:GridViewCommandColumn ShowSelectCheckbox="True" VisibleIndex="0" Width="40px" FixedStyle="Left"> <ClearFilterButton Visible="True"> </ClearFilterButton> <HeaderStyle HorizontalAlign="Center" /> <HeaderTemplate> <dx:ASPxCheckBox ID="chkSelectAll" runat="server" ClientSideEvents-CheckedChanged="function(s, e) { gvList.SelectAllRowsOnPage(s.GetChecked()); }" ToolTip="全选/取消全选" /> </HeaderTemplate> </dx:GridViewCommandColumn> <dx:GridViewDataTextColumn Caption="序号" VisibleIndex="1" Width="40px" FixedStyle="Left"> <EditFormSettings Visible="False" /> <DataItemTemplate> <%# Container.ItemIndex+1%> </DataItemTemplate> </dx:GridViewDataTextColumn> <dx:GridViewDataTextColumn Caption="记录流水号" FieldName="ydyxlsh" Visible="False" VisibleIndex="4"> <Settings AllowAutoFilter="False" /> </dx:GridViewDataTextColumn> <dx:GridViewDataDropDownEditColumn Caption="机器流水号" FieldName="cgjbxxlsh" VisibleIndex="8"> <Editformsettings Visible="True" VisibleIndex="1" /> <EditItemTemplate> <dx:ASPxComboBox ID="cgDrop" runat="server" EnableCallbackMode="true" CallbackPageSize="10" IncrementalFilteringMode="Contains" ValueType="System.String" OnItemsRequestedByFilterCondition="cgDrop_ItemsRequestedByFilterCondition" OnItemRequestedByValue="cgDrop_ItemRequestedByValue" TextFormatString="{0}" DropDownStyle="DropDownList" Theme="Aqua"> <Columns> <dx:ListBoxColumn FieldName="cgjbxxlsh" Caption="liushuihao" /> <dx:ListBoxColumn FieldName="sbbh" Caption="姓名" /> </Columns> </dx:ASPxComboBox> </EditItemTemplate> <Settings AllowAutoFilter="False" /> </dx:GridViewDataDropDownEditColumn> </Columns> <stylespopup> <EditForm> <ModalBackground Opacity="20"> </ModalBackground> </EditForm> </stylespopup> </dx:ASPxGridView> </div>
后台:
protected void gvList_InitNewRow(object sender, DevExpress.Web.Data.ASPxDataInitNewRowEventArgs e) { //暂时未写 } protected void cgDrop_ItemsRequestedByFilterCondition(object source, ListEditItemsRequestedByFilterConditionEventArgs e) { ASPxComboBox aspCom1 = gvList.FindEditRowCellTemplateControl(gvList.Columns["cgjbxxlsh"] as GridViewDataColumn, "aspCom") as ASPxComboBox; DataSet ds = new BLL.tb_cgjbxx().GetList("1=1"); //ds中存放的是B表中的所有数据 aspCom1.DataSource = ds; //将数据绑定到下列列表中 aspCom1.DataBind(); } protected void cgDrop_ItemRequestedByValue(object source, ListEditItemRequestedByValueEventArgs e) { ASPxComboBox aspCom = gvList.FindEditRowCellTemplateControl(gvList.Columns["cgjbxxlsh"] as GridViewDataColumn, "aspCom") as ASPxComboBox; DataSet ds = new BLL.tb_cgjbxx().GetList("1=1"); aspCom.DataSource = ds; aspCom.DataBind(); }
主要问题如下:
1、点击“添加”弹出提示窗口2,即添加窗口无法正常弹出,如果将其中的下列代码删除,则可以正常弹出添加窗口。<dx:ASPxComboBox ID="cgDrop" runat="server" EnableCallbackMode="true" CallbackPageSize="10" IncrementalFilteringMode="Contains" ValueType="System.String" OnItemsRequestedByFilterCondition="cgDrop_ItemsRequestedByFilterCondition" OnItemRequestedByValue="cgDrop_ItemRequestedByValue" TextFormatString="{0}" DropDownStyle="DropDownList" Theme="Aqua"> <Columns> <dx:ListBoxColumn FieldName="cgjbxxlsh" Caption="liushuihao" /> <dx:ListBoxColumn FieldName="sbbh" Caption="姓名" /> </Columns> </dx:ASPxComboBox>
2、如何在后台编写代码将数据绑定到“机器流水号”的下列列表中呢?我这里写的可能不对,谢谢!!
解决方案
这个错误是空指针异常,你调试下代码里有没有空值的情况。
时间: 2024-12-20 21:17:26