使用下拉列表使用另一个表中的值更新gridview [英] Update a gridview with values from another table using a drop down list

查看:107
本文介绍了使用下拉列表使用另一个表中的值更新gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Visual Studio 2010中使用ASP.Net 4.0。我的数据库中有两个表'registration'-table1 =="用户和QUOT;它有一个名为usertype的列,表2 ==请求它有一个名为assigned_to的列。



我打算做的是: - 当

页面加载时,显示网格视图,以及何时显示我点击编辑命令,assigned_to列包含一个下拉列表,显示来自Usertype ='服务商'的用户的firstname列的所有值。



现在点击下拉列表中的值,然后单击更新网格视图中的值不会更新。我没有在C#文件中使用任何代码。我只是使用网格视图的编辑模板功能。



请问任何身体帮助吗?

解决方案

< blockquote>你需要使用网格的RowCommand事件并在代码隐藏文件中写入更新逻辑。


< asp:gridview id =GridView1datasourceid =MyDataSourcedatakeynames =代码xmlns:asp =#unknown>

AutoGenerateColumns =falserunat =server>

< columns> < asp:commandfield buttontype =Linkshowsitbutton =trueshowcancelbutton =true>

< asp:boundfield datafield =Codeheadertext =Code>

< asp:boundfield datafield =Nameheadertext =Name>

< asp:boundfield datafield =描述headertext =Description>





< asp:sqldatasource id =MyDataSourcexmlns:asp =#unknown>

ConnectionString =<%


Connectionstrings:ERPConnectionString%>

SelectCommand =SELECT * FROM Sample

UpdateCommand =更新样本集名称= @名称,描述= @描述其中代码= @代码

DeleteCommand =删除代码=代码='代码runat =server/>



--------上面的方法就是当你在网格中分离出句法时,如果你没有在c#代码中进行任何编码你应该使用的东西类似于上面的一个。请注意'


I am using ASP.Net 4.0 in Visual Studio 2010. I have two tables in my database 'registration'- table1 ==" Users" which has a column called usertype and table 2=="Requests" which has a column called assigned_to.

What I intend to do is:- when the
page loads the grid view is shown and when I click the edit command, the assigned_to column contains a dropdown list showing all the values from the firstname column of Users where Usertype='facilitator'.

Now when I click the value in the drop down list and then click update the values in the grid view do not get updated. I am not using any code in the C# file. I am just using the edit template feature of the grid view.

please could any body help?

解决方案

You need to use RowCommand event of the grid and write the update logic in code behind file.


<asp:gridview id="GridView1" datasourceid="MyDataSource" datakeynames="Code" xmlns:asp="#unknown">
AutoGenerateColumns="false" runat="server">
<columns> <asp:commandfield buttontype="Link" showeditbutton="true" showcancelbutton="true">
<asp:boundfield datafield="Code" headertext="Code">
<asp:boundfield datafield="Name" headertext="Name">
<asp:boundfield datafield="Description" headertext="Description">


<asp:sqldatasource id="MyDataSource" xmlns:asp="#unknown">
ConnectionString="<%


Connectionstrings:ERPConnectionString%>"
SelectCommand="SELECT * FROM Sample"
UpdateCommand="Update SAMPLE SET Name=@Name,Description=@Description Where Code=@Code"
DeleteCommand="Delete SAMPLE Where Code=@Code" runat="server"/>

-------- The above way is when you sepcify soruce also in the grid, From your question if you are not doing any coding in c# Code you should be using something similar to one above. Please note the '


这篇关于使用下拉列表使用另一个表中的值更新gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆