C1GridView: 添加 DropdownList

我们可以添加多种单元格类型到 C1GridView。链接中的文档详细的阐述了C1GridView内置的单元格类型。在这些单元格类型中,C1TemplateField 可以通过定制来满足不同的用户需求。我们可以通过 C1TemplateField 下ItemTemplate 属性

发布于 2013/01/07 00:00

ComponentOne Enterprise

我们可以添加多种单元格类型到 C1GridView。链接中的文档详细的阐述了C1GridView内置的单元格类型。在这些单元格类型中,C1TemplateField 可以通过定制来满足不同的用户需求。我们可以通过 C1TemplateField  下ItemTemplate 属性,在 Grid 加载时绑定数据源到 C1TemplateField。同时,我们可以通过 EditItemTemplate 属性作为 C1TemplateField 的编辑器。可以参考 “<wijmo:C1GridView ID="C1GridView1" runat="server" AutogenerateColumns="False" DataKeyNames="CustomerID" DataSourceID="AccessDataSource1" OnRowUpdating="C1GridView1_RowUpdating"> <Columns> <wijmo:C1BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True" SortExpression="CustomerID"> </wijmo:C1BoundField> <wijmo:C1BoundField DataField="CustomerName" HeaderText="CustomerName" SortExpression="CustomerName"> </wijmo:C1BoundField> <wijmo:C1TemplateField HeaderText="Country"> <ItemTemplate> <span> <%# Eval("Country") %></span> </ItemTemplate> <EditItemTemplate> <asp:DropDownList ID="dlCountry" runat="server" DataSourceID="AccessDataSource2" DataTextField="Country" DataValueField="Country" SelectedValue='<%# Bind("Country") %>'> </asp:DropDownList> <asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="~/App_Data/C1NWind1.mdb" SelectCommand="SELECT * FROM [Countries]"></asp:AccessDataSource> </EditItemTemplate> </wijmo:C1TemplateField> <wijmo:C1CommandField ShowEditButton="True"> </wijmo:C1CommandField> </Columns> </wijmo:C1GridView> <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/C1NWind1.mdb" SelectCommand="SELECT * FROM [Customers]" > </asp:AccessDataSource>

下列图片展示了允许程序的初始界面:

 

下面,我们可以点击 Edit 按钮使 C1GridView 更新到编辑状态。我们可以看到 DropDownList 弹出,通过 DropDownList 我们可以选择目标项。截图:

 

在选择目标选项后,点击 Update 按钮完成更新,此时,我们需要通过 UpdateCommand 事件来更新数据源,实现代码如下:

protected void C1GridView1_RowUpdating(object sender, C1.Web.Wijmo.Controls.C1GridView.C1GridViewUpdateEventArgs e)
    {
      AccessDataSource1.UpdateCommand = "Update Customers Set CustomerName=@CustomerName, Country=@Country where CustomerID=@CustomerID";
      AccessDataSource1.UpdateParameters.Add("CustomerID",e.Keys["CustomerID"].ToString());
      AccessDataSource1.UpdateParameters.Add("CustomerName", e.NewValues["CustomerName"].ToString());
      AccessDataSource1.UpdateParameters.Add("Country", e.NewValues["Country"].ToString());
      AccessDataSource1.Update();
    }
 

更详细信息请参考 Demo:

Download Sample

ComponentOne Enterprise | 下载试用

ComponentOne 是一套专注于企业 .NET开发、支持 .NET Core 平台,并完美集成于 Visual Studio 的第三方控件集,包含 300 多种 .NET开发控件,提供表格数据管理、数据可视化、报表和文档、日程安排、输入和编辑、导航和布局、系统提升工具等七大功能,被誉为“.NET开发的‘瑞士军刀’”。

ComponentOne 为您提供专业的产品咨询服务,并由技术支持工程师为您1对1解答。>> 发帖提问

相关产品
推荐相关案例
关注微信
葡萄城社区二维码

关注“葡萄城社区”

加微信获取技术资讯

加微信获取技术资讯

想了解更多信息,请联系我们, 随时掌握技术资源和产品动态