I'm populate listview from stored procedure in code behind. Everything is working fine. However,In this listview, I have a dropdownlist populate from SqlDataSource1, but I cannot set the dropdownlist selectedText properly. How can I set this dropdownlist SelectedText?
This is aspx
<asp:ListView ID="ListView1" runat="server">
<layouttemplate>
<tr ID="itemPlaceholder" runat="server">
Staff | Top 1 | Top 2 | Top 3 | Top 4 | Peer 1 | Peer 2 | Peer 3 | Peer 4 | Bottom 1 | Bottom 2 | Bottom 3 | Bottom 4 |
<itemtemplate>
<asp:Label ID="lbl_name" runat="server" Text='<%#Eval("name")%>'>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="name" DataValueField="staff_id" SelectedText='<%# Eval("t1") %>'> <asp:Label ID="lbl_t2" runat="server" Text='<%#Eval("t2")%>'>
<asp:Label ID="lbl_t3" runat="server" Text='<%#Eval("t3")%>'>
<asp:Label ID="lbl_t4" runat="server" Text='<%#Eval("t4")%>'>
<asp:Label ID="lbl_p1" runat="server" Text='<%#Eval("p1")%>'>
<asp:Label ID="lbl_p2" runat="server" Text='<%#Eval("p2")%>'>
<asp:Label ID="lbl_p3" runat="server" Text='<%#Eval("p3")%>'> <asp:Label ID="lbl_p4" runat="server" Text='<%#Eval("p4")%>'> <asp:Label ID="lbl_b1" runat="server" Text='<%#Eval("b1")%>'> <asp:Label ID="lbl_b2" runat="server" Text='<%#Eval("b2")%>'> <asp:Label ID="lbl_b3" runat="server" Text='<%#Eval("b3")%>'> <asp:Label ID="lbl_b4" runat="server" Text='<%#Eval("b4")%>'>
<alternatingitemtemplate>
<asp:Label ID="lbl_name" runat="server" Text='<%#Eval("name")%>'>
<asp:Label ID="lbl_t1" runat="server" Text='<%#Eval("t1")%>'> <asp:Label ID="lbl_t2" runat="server" Text='<%#Eval("t2")%>'>
<asp:Label ID="lbl_t3" runat="server" Text='<%#Eval("t3")%>'>
<asp:Label ID="lbl_t4" runat="server" Text='<%#Eval("t4")%>'>
<asp:Label ID="lbl_p1" runat="server" Text='<%#Eval("p1")%>'>
<asp:Label ID="lbl_p2" runat="server" Text='<%#Eval("p2")%>'>
<asp:Label ID="lbl_p3" runat="server" Text='<%#Eval("p3")%>'> <asp:Label ID="lbl_p4" runat="server" Text='<%#Eval("p4")%>'> <asp:Label ID="lbl_b1" runat="server" Text='<%#Eval("b1")%>'> <asp:Label ID="lbl_b2" runat="server" Text='<%#Eval("b2")%>'> <asp:Label ID="lbl_b3" runat="server" Text='<%#Eval("b3")%>'> <asp:Label ID="lbl_b4" runat="server" Text='<%#Eval("b4")%>'>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:PerformanceConnectionString %>" SelectCommand="select distinct s.staff_id as staff_id,s.name as name from staff_assign a
join staff s on a.staff_id = s.staff_id
join dept d on d.dept_head_id = @dept_head_id">
<SelectParameters>
<asp:QueryStringParameter Name="dept_head_id" QueryStringField="dept_head_id" />
</SelectParameters>
this is code behind:
protected void get_data()
{
DataTable dt = new DataTable();
SqlCommand cmd2 = new SqlCommand();
SqlDataAdapter adp = new SqlDataAdapter();
SqlConnection con2 = new SqlConnection(strCon);
try
{
cmd2 = new SqlCommand("get_relationship", con2);
cmd2.CommandType = CommandType.StoredProcedure;
cmd2.Parameters.AddWithValue("@dept_head_id", Request.QueryString["dept_head_id"].ToString());
adp.SelectCommand = cmd2;
adp.Fill(dt);
ListView1.DataSource = dt;
ListView1.DataBind();
}
catch (Exception ex)
{
}
finally
{
dt.Clear();
dt.Dispose();
cmd2.Dispose();
con2.Close();
}
}