Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dropdownlist in a Gridview

Status
Not open for further replies.

technisup

Programmer
Sep 28, 2007
41
US
Hello, I'm adding in a gridview a dropdownlist that has its own SqlDataSource, the idea of this not to display this:



TABLE: TipoPropuesta

ID Descripcion IdGrupo
1 Datacenter Services 3



But to display this:

ID Descripcion IdGrupo
1 Datacenter Services Callcenter



The table TipoPropuesta is related with the table Group and from this i'm feeding my dropdownlist in order to select the group, the thing is that I have already this, but when I try to update the record is not doing updating it.

This is my code:
Code:
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="SIP :: Consulta de Sector" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
    <a href="Sector.aspx"><span style="font-size: 24pt">Sector</span></a><span style="font-size: 24pt">
        :: Consultas<br />
        <br />
        &nbsp; &nbsp;
        <br />
        <asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:SIPConnectionString %>"
            SelectCommand="SELECT * FROM [Grupo]"></asp:SqlDataSource>
        &nbsp; &nbsp;
        &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;<br />
        <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:SIPConnectionString %>" 
             SelectCommand="SELECT TipoPropuesta.IdTipoPropuesta AS Expr2, TipoPropuesta.Descripcion AS Expr3, TipoPropuesta.IdGrupo, Grupo.Descripcion AS Expr1 FROM TipoPropuesta INNER JOIN Grupo ON TipoPropuesta.IdGrupo = Grupo.IdGrupo" 
             UpdateCommand="UPDATE [TipoPropuesta] SET [Descripcion] = @Descripcion, [IdGrupo] = @IdGrupo WHERE [IdTipoPropuesta] = @IdTipoPropuesta">
            <UpdateParameters>
                <asp:Parameter Name="Descripcion" />
                <asp:Parameter Name="IdGrupo" />
                <asp:Parameter Name="IdTipoPropuesta" />
            </UpdateParameters>
        </asp:SqlDataSource>
        <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="Expr2"
            DataSourceID="SqlDataSource3" Style="position: static">
            <Columns>
                <asp:CommandField ShowEditButton="True" />
                <asp:BoundField DataField="Expr2" HeaderText="Expr2" InsertVisible="False" ReadOnly="True"
                    SortExpression="Expr2" />
                <asp:BoundField DataField="Expr3" HeaderText="Expr3" SortExpression="Expr3" />
                <asp:TemplateField HeaderText="Expr1" SortExpression="Expr1">
                    <EditItemTemplate>
                        <asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlDataSource4"
                            DataTextField="Descripcion" DataValueField="IdGrupo"
                            Style="position: static" SelectedValue='<%# Bind("IdGrupo") %>'>
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("Expr1") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="IdGrupo" HeaderText="IdGrupo" SortExpression="IdGrupo" />
            </Columns>
        </asp:GridView>
        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
        &nbsp; &nbsp; &nbsp; &nbsp;
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;
    </span>
</asp:Content>

How can i solve this?

 
How can i solve this?
Don't use the datasource controls. You can't debug them and they are hard to customize beyond simple display of data.

Use code to create a dataset or datatable and bind that to your grid. Then write any stored procedures to Select/Insert/Update/Delete your data.

Have a look into Microsoft's data application block:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top