databounded DropDownList in EditItemTemplate of a dataList

Last post 07-08-2008 9:22 PM by Qin Dian Tang - MSFT. 3 replies.

Sort Posts:

  • databounded DropDownList in EditItemTemplate of a dataList

    07-03-2008, 12:29 AM
    • Member
      point Member
    • h891
    • Member since 07-03-2008, 4:18 AM
    • Posts 2

    hello. I want to have a databounded DropDownList in EditItemTemplate of a Data list .the time of my databinding is on page_load ..but i encounter with some errors :

     

    The data source 'SqlDataSource1' only supports a single view named 'DefaultView'.
    You may also leave the view name (also called a data member)
    empty for the default view to be chosen.
    Parameter name: viewName

     

     and my language is vb.net how shoud i write coed to achieve this feature?please help me .thank

  • Re: databounded DropDownList in EditItemTemplate of a dataList

    07-07-2008, 5:27 AM
    Answer

    Hi h891,

    I think you can bind DropDownList in Click event of Edit Button in DataList. Here is a sample:

    <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1">
            <ItemTemplate>
              <asp:Label runat="server" ID="id" Text='<%# Eval("ID") %>'></asp:Label>
              <asp:Button runat="server" ID="Button1" Text="Edit" OnClick="Button1_Click" />
            </ItemTemplate>
            <EditItemTemplate>
              <asp:Label runat="server" ID="id" Text='<%# Eval("ID") %>'></asp:Label>
              <asp:DropDownList runat="server" ID="nameDDL"></asp:DropDownList>
            </EditItemTemplate>
    </asp:DataList>

     Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim dli As DataListItem = DirectCast(DirectCast(sender, Button).Parent, DataListItem)
        DataList1.EditItemIndex = dli.ItemIndex
         'turn to edit mode in this item
        DataList1.DataBind()
        Dim dt As DataTable = DirectCast((SqlDataSource2.[Select](DataSourceSelectArguments.Empty)), DataView).Table  'get datatable from SqldataSource control
        Dim ddl As DropDownList = DirectCast(DataList1.Items(DataList1.EditItemIndex).FindControl("nameDDL"), DropDownList)       'set databinding for dropdownlist
        ddl.DataSource = dt
        ddl.DataTextField = "Name"
        ddl.DataBind()
    End Sub

    Thanks,

    Qin Dian Tang
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: databounded DropDownList in EditItemTemplate of a dataList

    07-08-2008, 2:44 PM
    • Member
      point Member
    • h891
    • Member since 07-03-2008, 4:18 AM
    • Posts 2

    hello dear Qin Dian Tang -MSFT

    i forgot to point two things :

    1 ( and important)- i'm beginner in vb.net programming and

    2- i'm now working with  vb.net version 2005

    thank you for answer . i apply all above code to solve my problem so carefully. but i get a new error :

    Invalid postback or callback argument. 
    Event validation is enabled using <pages enableEventValidation="true"/>
    in configuration or <%@ Page EnableEventValidation="true" %> in a page. 
    For security purposes, this feature verifies that arguments to postback or
    callback events originate from the server control that originally rendered them. 
    If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation
    method in order to register the postback or callback data for validation.

    attention that  : i want to have this :

    my datalist be databounded with table1

    and my dropdownlist be databounded by a column of table2  

    thanks

     

  • Re: databounded DropDownList in EditItemTemplate of a dataList

    07-08-2008, 9:22 PM

    Hi h891,

    Try to set EnableEventValidation="false" in your page tag of .aspx. In my sample I do use two different tables. As you can see two different SqlDataSource control (SqlDataSource1&SqlDataSource2). You just need to give two selectcommand in these two data source controls with two tables.

    Thanks,

    Qin Dian Tang
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Page 1 of 1 (4 items)