RE: bind dropdown field in GridView EditItemTemplate?

Discussion in 'ASP .Net' started by =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=, Mar 21, 2006.

  1. The GridView will pass the LessorID as a parameter (in the NewValues
    collection) if you create a 2-way databind on the dropdownlist:

    <asp:DropDownList ID="ddlCompany" runat="server"
    DataSourceID="sdsLessors" DataTextField="Company" DataValueField="LessorId"
    SelectedValue='<%# Bind("LessorID") %>'>
    </asp:DropDownList>

    In addition, for good programming style, you should define an
    <UpdateParameters> collection within the markup of the SqlDatasource that
    updates the GridView.

    --
    HTH,
    Phillip Williams
    http://www.societopia.net
    http://www.webswapp.com


    "Dabbler" wrote:

    > I have two tables I'm editing in a Gridview. The VANS table contains a key to
    > the other LESSOR table. I would like to use a dropdown list to select the
    > LessorId value while displaying the Lessor table's "Company" field as text.
    > When I commit the edit I get error:Must declare the scalar variable
    > "@LessorId".
    >
    > Also as a bonus question ;) I don't know how to set the selectedindex value
    > in the dropdown list based on the LessorId value in the Vans table.
    >
    > Any ideas would be appreciated!
    >
    > Thanks.
    >
    > Here's my templatefield:
    > <asp:TemplateField HeaderText="Company" >
    > <ItemTemplate>
    > <asp:literal ID="Literal1" runat="server" Text='<%# Eval("Company") %>' />
    > </ItemTemplate>
    > <EditItemTemplate>
    > <asp:DropDownList ID="ddlCompany" runat="server"
    > DataSourceID="sdsLessors" DataTextField="Company" DataValueField="LessorId">
    > </asp:DropDownList>
    > </EditItemTemplate>
    > </asp:TemplateField>
    >
    > Gridview's SqlDataSource:
    > <asp:SqlDataSource ID="sdsVans" runat="server"
    > ProviderName="System.Data.SqlClient"
    > ConnectionString="<%$ ConnectionStrings:myDB %>"
    > SelectCommand="SELECT v.VanNo, v.LessorId, v.Status, v.Active,
    > l.Company, l.Account FROM dbo.Van v join dbo.Lessors l ON
    > v.LessorId=l.LessorId order by VanNo"
    > UpdateCommand="Update dbo.Vans set VanNo=@VanNo, LessorId=@LessorId,
    > Status=@Status,Active=@Active where LessorId=@LessorId" >
    > </asp:SqlDataSource>
    >
    > DropDownList's SqlDataSource:
    > <asp:SqlDataSource ID="sdsLessors" runat="server"
    > ProviderName="System.Data.SqlClient"
    > ConnectionString="<%$ ConnectionStrings:myDB %>"
    > SelectCommand="SELECT LessorId, Company, Account FROM dbo.Lessors
    > order by Company">
    > </asp:SqlDataSource>
     
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=, Mar 21, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vishnu
    Replies:
    1
    Views:
    1,214
    Patrick.O.Ige
    Mar 25, 2006
  2. =?Utf-8?B?RGFiYmxlcg==?=

    bind dropdown field in GridView EditItemTemplate?

    =?Utf-8?B?RGFiYmxlcg==?=, Mar 21, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    30,113
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    Mar 23, 2006
  3. Replies:
    0
    Views:
    947
  4. sjmyers
    Replies:
    0
    Views:
    1,757
    sjmyers
    Mar 27, 2007
  5. Brian Greiwe

    Can't get to nested dropdown in edititemtemplate column

    Brian Greiwe, Sep 16, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    157
    Brian Greiwe
    Sep 16, 2003
Loading...

Share This Page