Update命令不适用于下拉列表

Update命令不适用于下拉列表

本文介绍了Gridview Update命令不适用于下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一个gridview,绑定到datasource1,两个表有一个内连接,在那个网格中有3列(2个文本框)和1个下拉列表。

我需要在编辑时将值更新到数据库中。第三列是下拉列表,绑定到另一个数据,即datasouce2。



我在sql management studio中尝试了相同的sql查询及其完美更新的文本框和下拉列表值得当我在Gridview更新命令中写入相同的查询时它不起作用。



我面临的问题是,如果我不能更新下拉列表改变价值。



有人可以帮助我。





这是我写的代码。在此先感谢。

Hi All,

I have a gridview with is binded to datasource1 for two tables with a inner join and in that grid there are 3 columns ( 2 text boxes and 1 dropdownlist).
I need to update the values into the databse on edit. The 3rd column which is dropdownlist is binded to another datasouce which is datasouce2.

I have tried the same sql query in sql management studio and its perfectly updating text box and dropdownlist value when when the same query i am writing in Gridview update command its not working.

The problem I am facing is , I am not able to update the dropdownlist if i change the value.

Can someone please help me.


Here is the code which I have written. Thanks in advance.

 <asp:GridView ID="gvProducts" runat="server" AutoGenerateEditButton="True" AutoGenerateColumns="False"
                OnRowEditing="gvProducts_RowEditing"
            OnRowUpdating="gvProducts_RowUpdating" CellPadding="1"
                ForeColor="#333333" GridLines="None" DataSourceID="SqlDataSource1"
            Height="75px" Width="660px" DataKeyNames="BCode" AllowPaging="True"
            PageSize="20">
                <RowStyle BackColor="#EFF3FB" />
                <Columns>
                    <%--<asp:BoundField DataField="TName" HeaderText="Branch Group"
                        SortExpression="TName" />  --%>

                    <asp:BoundField DataField="BCode" HeaderText="BCode" ReadOnly="True"
                        SortExpression="BCode" />
                    <asp:BoundField DataField="BName" HeaderText="BName"
                        SortExpression="BName" />

                    <asp:TemplateField HeaderText="Branchgroup">
                    <EditItemTemplate>
                        <asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True"  DataSourceID="SqlDataSource2" DataTextField="TName" DataValueField="TCode" Width="120px" Height="25px" AutoPostBack="True" >
                        <asp:ListItem> </asp:ListItem>
                        </asp:DropDownList>

                    </EditItemTemplate>
                    <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("TName") %>'></asp:Label>
                    </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                <EditRowStyle BackColor="#2461BF" />
                <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                <PagerSettings FirstPageText="First</br>" LastPageText="Last </br>"
                    Mode="NextPrevious" NextPageText="Next</br>"
                    PreviousPageText="Previous </br>" />
                <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White"
                    HorizontalAlign="Left" />
                <AlternatingRowStyle BackColor="White" />
                <SortedAscendingCellStyle BackColor="#F5F7FB" />
                <SortedAscendingHeaderStyle BackColor="#6D95E1" />
                <SortedDescendingCellStyle BackColor="#E9EBEF" />
                <SortedDescendingHeaderStyle BackColor="#4870BE" />
            </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"
            ConnectionString="<%$ %>"
            SelectCommand="SELECT Branch.BCode, Branch.BName, Tab.TName FROM Branch LEFT OUTER JOIN Tab ON Branch.TCode = Tab.TCode ORDER BY Branch.BCode"
             UpdateCommand="UPDATE Branch set BName=@BName, TCode = (SELECT top 1 Tcode FROM Tab WHERE ( TNAme = @TName) AND (ACode = @ACode)) where ( BCode =@BCode)and (ACode=@Code)">
    <UpdateParameters>
                <asp:Parameter Name="BName" />
                <asp:Parameter Name="TName" />
                <asp:Parameter Name="ACode" />
                <asp:Parameter Name="BCode" />
            </UpdateParameters>
        </asp:SqlDataSource>
     <asp:SqlDataSource ID="SqlDataSource2" runat="server"
        ConnectionString="<%$ %>"

            SelectCommand="SELECT DISTINCT [TName], [TCode] FROM [Tab] ORDER BY [TName]" >

        </asp:SqlDataSource>


code behind:


protected void gvProducts_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {



        }


        private void gvProducts_DataBind(string control, int index)
        {

        }

推荐答案



这篇关于Gridview Update命令不适用于下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 19:49