EditItemTemplate's DropDownList problem

A

asp.net

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>

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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top