111,131
社区成员
发帖
与我相关
我的任务
分享
String suject=String.Empty;//保存你查询条件的变量
this.SqlDataSource1.SelectParameters["subject"].DefaultValue =suject;//这个就是给subject传值
this.SqlDataSource1.DataBind();
DropDownList1.DataBind();
try
{
string connStr = System.Configuration.ConfigurationManager.ConnectionStrings["connnane"];
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connStr);
//System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("select [name_id],[gj_name] from [gj_name] where subject='" + Request["subjectid"].ToString + "'", conn);
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter("select [name_id],[gj_name] from [gj_name] where subject='" + Request["subjectid"].ToString + "'", conn);
System.Data.DataSet ds = null;
da.Fill(ds);
this.DropDownList1.DataSource = ds.Tables[0];
this.DropDownList1.DataTextField = "gj_name";
this.DropDownList1.DataValueField = "name_id";
this.DropDownList1.DataBind();
}
catch (Exception ex)
{
}
<asp:DropDownList ID="hp_grouInfo_gj_name" runat="server" RepeatLayout="Flow" RepeatColumns="5"
Width="100%" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="gj_name" DataValueField="gj_name">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString=" <%$ ConnectionStrings:Jcjg_JMConnectionString %>"
SelectCommand="SELECT [gj_name] FROM [gj_name] WHERE ([subject] = @subject)">
<SelectParameters>
<asp:Parameter DefaultValue="自己填认值" Name="subject" Type="你subject字段的数据类型" />
</SelectParameters>
</asp:SqlDataSource>
String suject=String.Empty;
this.SqlDataSource1.SelectParameters["subject"].DefaultValue =suject;//这个就是给参数的赋值语句
this.SqlDataSource1.DataBind();
再绑定你的DropDownList