如何在listview中设置dropdownlist SelectedText [英] How to set dropdownlist SelectedText in listview
问题描述
我在代码后面的存储过程中填充listview。一切都很好。但是,在这个listview中,我有一个从SqlDataSource1填充的下拉列表,但我无法正确设置下拉列表selectedText。如何设置此下拉列表SelectedText?
这是aspx
< asp:ListView ID =ListView1runat =server >
< layouttemplate>
< tr ID =itemPlaceholderrunat =server>
员工 | Top 1 | Top 2 | Top 3 | >对等3第4对等第4个第1个第2个第2个第3个第3个第4个 | 第4个第4个 th>
---|
< itemtemplate>
< asp:标签ID =lbl_namerunat =serverText ='<%#Eval(name)%>'>
< asp:DropDownList ID =DropDownList1runat =serverDataSourceID =SqlDataSource1DataTextField =nameDataValueField =staff_idSelectedText ='< ;%#Eval(t1)%>'> < asp:Label ID =lbl_t2runat =serverText ='<%#Eval(t2)%>'>
< asp:Label ID =lbl_t3runat =serverText ='<%#Eval(t3)%>'>
< asp:Label ID =lbl_t4runat =serverText ='<%#Eval(t4)%>'>
< asp:Label ID =lbl_p1runat =serverText ='<%#Eval(p1)%>'>
< asp:Label ID =lbl_p2runat =serverText ='<%#Eval(p2)%>'>
< asp:Label ID =lbl_p3runat =serverText ='<%#Eval(p3)%>'> < asp:Label ID =lbl_p4runat =serverText ='<%#Eval(p4)%>'> < asp:Label ID =lbl_b1runat =serverText ='<%#Eval(b1)%>'> < asp:Label ID =lbl_b2runat =serverText ='<%#Eval(b2)%>'> < asp:Label ID =lbl_b3runat =serverText ='<%#Eval(b3)%>'> < asp:Label ID =lbl_b4runat =serverText ='<%#Eval(b4)%>'>
< alternatingitemtemplate>
< asp:Label ID =lbl_namerunat =server Text ='<%#Eval(name)%>'>
< asp:Label ID =lbl_t1runat =serverText ='<%#Eval(t1)%>'> < asp:Label ID =lbl_t2runat =serverText ='<%#Eval(t2)%>'>
< asp:Label ID =lbl_t3runat =serverText ='<%#Eval(t3)%>'>
< asp:Label ID =lbl_t4runat =serverText ='<%#Eval(t4)%>'>
< asp:Label ID =lbl_p1runat =serverText ='<%#Eval(p1)%>'>
< asp:Label ID =lbl_p2runat =serverText ='<%#Eval(p2)%>'>
< asp:Label ID =lbl_p3runat =serverText ='<%#Eval(p3)%>'> < asp:Label ID =lbl_p4runat =serverText ='<%#Eval(p4)%>'> < asp:Label ID =lbl_b1runat =serverText ='<%#Eval(b1)%>'> < asp:Label ID =lbl_b2runat =serverText ='<%#Eval(b2)%>'> < asp:Label ID =lbl_b3runat =serverText ='<%#Eval(b3)%>'> < asp:Label ID =lbl_b4runat =serverText ='<%#Eval(b4)%>'>
< asp:SqlDataSource ID =SqlDataSource1runat =serverConnectionString =<%$ ConnectionStrings:PerformanceConnectionString% >中SelectCommand =选择不同的s.staff_id作为staff_id,s.name作为名称来自staff_assign a
加入员工的a.staff_id = s.staff_id
加入dept d on d.dept_head_id = @dept_head_id>
< SelectParameters>
< asp:QueryStringParameter Name =dept_head_idQueryStringField =dept_head_id/>
< / SelectParameters>
这是代码背后:
protected void get_data()
{
DataTable dt = new DataTable() ;
SqlCommand cmd2 = new SqlCommand();
SqlDataAdapter adp = new SqlDataAdapter();
SqlConnection con2 = new SqlConnection(strCon);
尝试
{
cmd2 =新的SqlCommand(get_relationship,con2);
cmd2.CommandType =逗号ndType.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)
{
}
终于
{
dt.Clear();
dt.Dispose();
cmd2.Dispose();
con2.Close();
}
}
ConnectionStrings:PerformanceConnectionString%>SelectCommand =选择不同的s.staff_id作为staff_id ,s.name为名称fr om staff_assign a
加入职员s.staff_id = s.staff_id
加入dept d on d.dept_head_id = @dept_head_id>
< SelectParameters>
< asp:QueryStringParameter Name =dept_head_idQueryStringField =dept_head_id/>
< / SelectParameters>
这是代码背后:
protected void get_data ()
{
DataTable dt = new DataTable();
SqlCommand cmd2 = new SqlCommand() ;
SqlDataAdapter adp = new SqlDataAdapter();
SqlConnection con2 = new SqlConnection(strCon);
尝试
{
cmd2 =新的SqlCommand(get_relationship,con2);
cmd2.CommandType = CommandType.StoredProcedure;
cmd2.Parameters.AddWit hValue(@ dept_head_id,Request.QueryString [dept_head_id]。ToString());
adp.SelectCommand = cmd2 ;
adp.Fill(dt);
ListView1.DataSource = dt;
ListView1.DataBind( );
}
catch(例外情况)
{
< br $>
}
终于
{
dt.Clear();
dt。 Dispose();
cmd2.Dispose();
con2.Close();
}
}
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();
}
}
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();
}
}
这篇关于如何在listview中设置dropdownlist SelectedText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!