EditItemTemplate's DropDownList problem

Discussion in 'ASP .Net Datagrid Control' started by asp.net, Mar 9, 2005.

  1. asp.net

    asp.net Guest

    I have follow the instruction from the web.


    When I was trying to implement new codes in order to fit my problems,
    error occurs.
    I was trying to mount 3 dropdownlist. Pls have a look at the following

    <vb code>
    Dim ds as DataSet = New DataSet()
    Dim m_id As String
    Dim dbconn As OleDbConnection

    Function GetCategories(type As String) as DataSet

    Dim sql as String = "SELECT * FROM [" & type & "Detail]"
    Dim myDataAdapter as OleDbDataAdapter = New OleDbDataAdapter(sql,
    myDataAdapter.Fill(ds, type)

    Return ds

    End Function

    Function GetSelectedIndex(CID as String, type as string) as Integer
    Dim iLoop as Integer

    Dim dt as DataTable = ds.Tables(type)
    For iLoop = 0 to dt.Rows.Count - 1
    If Int32.Parse(CID) = Int32.Parse(dt.Rows(iLoop)("ID")) then
    Return iLoop
    End If
    Next iLoop

    End Function

    Sub BindList()
    dim dataAdaptor As OleDbDataAdapter
    dim dss As DataSet
    dim sql As String

    sql="SELECT APAC.*, IIf(IsNull(APAC.[Source]),1,SourceDetail.ID) AS
    [Source ID], " &_
    "IIf(IsNull(APAC.[Keyword 1]),1,[Keyword1Detail].ID) AS [Keyword 1 ID],
    " &_
    "IIf(IsNull(APAC.[Keyword 2]),1,[Keyword2Detail].ID) AS [Keyword 2 ID]
    FROM " &_
    "((APAC LEFT JOIN SourceDetail ON APAC.Source = SourceDetail.Source)
    LEFT JOIN " &_
    "[Keyword1Detail] ON APAC.[Keyword 1] = [Keyword1Detail].[Keyword 1])
    LEFT JOIN " &_
    "[Keyword2Detail] ON APAC.[Keyword 2] = [Keyword2Detail].[Keyword 2]
    WHERE APAC.ID = " & m_id
    dataAdaptor=New OleDbDataAdapter( sql, dbconn )
    dss=New DataSet

    MyDataList.DataSource = dss.Tables("details").DefaultView
    End Sub


    <html code>

    <div style="padding:15,15,15,15;font-size:10pt;font-family:Verdana">
    <div style="font:12pt verdana;color:darkred">
    <br />
    Keyword 1:
    <asp:DropDownList runat="server" id="Keyword1" DataValueField="ID"
    DataTextField="Keyword 1"
    DataSource='<%# GetCategories("Keyword1") %>'
    SelectedIndex='<%# GetSelectedIndex(Container.DataItem("Keyword 1
    ID"),"Keyword1") %>' />
    <br />
    Keyword 2:
    <asp:DropDownList runat="server" id="Keyword2" DataValueField="ID"
    DataTextField="Keyword 2" DataSource='<%# GetCategories("Keyword2") %>'
    SelectedIndex='<%# GetSelectedIndex(Container.DataItem("Keyword 2
    ID"),"Keyword2") %>' />
    <br />
    <asp:DropDownList runat="server" id="source" DataValueField="ID"
    DataTextField="Source" DataSource='<%# GetCategories("Source") %>'
    SelectedIndex='<%# GetSelectedIndex(Container.DataItem("Source
    ID"),"Source") %>' />
    <br />
    <asp:TextBox id="question" textmode="MultiLine" AutoPostBack="true"
    width="100%" height="200" Text='<%# DataBinder.Eval(Container.DataItem,
    "Question") %>' runat="server" />
    <br />
    <asp:TextBox id="answer" textmode="MultiLine" AutoPostBack="true"
    width="100%" height="200" Text='<%# DataBinder.Eval(Container.DataItem,
    "Answer") %>' runat="server" />
    <asp:linkbutton CommandName="Update" runat="server">
    <img border="0" src="update_book.gif" />
    <asp:linkbutton CommandName="Cancel" runat="server">
    <img border="0" src="cancel_book.gif" />

    Sub BindList.
    But the code works fine when there's only one dropdown box in

    asp.net, Mar 9, 2005
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.