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.

    http://aspnet.4guysfromrolla.com/demos/dgExample16.aspx

    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
    code.


    <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,
    dbconn)
    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
    dataAdaptor.Fill(dss,"details")

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

    </code>


    <html code>

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

    </code>

    >From the error message I obtained, the error should be caused by the

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

    Thans
    asp.net, Mar 9, 2005
    #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. =?Utf-8?B?ZGVuIDIwMDU=?=

    No Value: DropDownlist in EditItemTemplate Gridview Problem

    =?Utf-8?B?ZGVuIDIwMDU=?=, Oct 11, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    525
    =?Utf-8?B?ZGVuIDIwMDU=?=
    Oct 11, 2006
  2. Jeff
    Replies:
    0
    Views:
    378
  3. Trevor Bezotte

    DetailsView EditItemTemplate DropdownList Update Problem

    Trevor Bezotte, Dec 1, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    9
    Views:
    308
    Steven Cheng[MSFT]
    Dec 8, 2005
  4. den 2005
    Replies:
    0
    Views:
    204
    den 2005
    Oct 11, 2006
  5. den 2005

    DropDownlist in EditItemTemplate Gridview Problem

    den 2005, Oct 11, 2006, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    278
    Antoine Griffard
    Oct 11, 2006
Loading...

Share This Page