将数据检索到datagridview,使用组合框列显示,编辑和保存。 [英] Retrieve data into datagridview, display using combobox column, edit and save.
本文介绍了将数据检索到datagridview,使用组合框列显示,编辑和保存。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有代码来检索数据并在datagridview中显示,比如这个
I have code to retrieve data and display in a datagridview, like this
string queryString;
SqlConnection myConnection = new SqlConnection();
myConnection.ConnectionString = global.constr;
queryString = "";
queryString = " SELECT [ID],[CustomerName],[ProductName],[W1],[W2],[W3],[W4],[W5]FROM [cos].[dbo].[tbl_cs] ";
queryString = queryString + " where CustomerName='" + global.ValueToShare + "' ";
SqlCommand command = new SqlCommand(queryString, myConnection);
command.Connection.Open();
SqlDataReader dreader = command.ExecuteReader();
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(string));
dt.Columns.Add("CustomerName", typeof(string));
dt.Columns.Add("ProductName", typeof(string));
dt.Load(dreader);
command.Connection.Close();
command.Connection.Dispose();
工作正常。但我想做的是;
将[CustomerName]和[ProductName]列显示为组合框,这些组合框具有来自各个表格的来源,如Table_Customers& Table_Products。
如果用户想要更改这两个中的任何一个,他点击下拉列表,选择新值并更新数据库。
请建议如何完成
It works fine. But what I wish to do is;
Display the columns [CustomerName] &[ProductName] as combobox, these comboboxes have a source from respective tables like Table_Customers & Table_Products.
If the user want to change any of these two, he click the dropdown list, select the new value and update the database.
Please suggest how it will be done
推荐答案
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource1" DataTextField="nazwa" DataValueField="nazwa"
SelectedValue='<%# Bind("nazwa") %>'>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%
ConnectionStrings:baza_pismConnectionString1 %>
SelectCommand = SELECT [nazwa] FROM [podmioty] > < / asp:SqlDataSource >
< / EditItemTemplate >
ConnectionStrings:baza_pismConnectionString1 %>" SelectCommand="SELECT [nazwa] FROM [podmioty]"></asp:SqlDataSource> </EditItemTemplate>
这篇关于将数据检索到datagridview,使用组合框列显示,编辑和保存。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文