<asp:DropDownList ID="DropDownList1" runat="server" Width="128px" Height="32px"
onselectedindexchanged="DropDownList1_SelectedIndexChanged"
style="position: relative; top: 3px; left: 4px">
<asp:ListItem>.......SELECT.......</asp:ListItem>
<asp:ListItem>Membership</asp:ListItem>
<asp:ListItem>Publication</asp:ListItem>
<asp:ListItem>Journal</asp:ListItem>
<asp:ListItem>Additional Activity</asp:ListItem>
<asp:ListItem>Guide Details</asp:ListItem>
<asp:ListItem>Project</asp:ListItem>
<asp:ListItem>Workshop</asp:ListItem>
//c# code to call the list items
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedIndex == Convert.ToInt32(0))
{
}
}
2536 次
3 に答える
0
データベースまたはコレクションからデータを取得します。ドロップダウン リストのデータ ソース プロパティをそのソースに設定します。
List<strig> data = // set list from db or from any collection.
DropdownList1.DataSource=data;
DropdownList1.DtataBind();
これにより、コンテンツがソースからドロップダウン リストに読み込まれます。ソースは任意のコレクションにすることができます。
ドロップダウン リストの DataTextField と DataValueFiled を設定して、ドロップ ダウン項目が選択されたときにコレクションのどのプロパティをテキストとして表示し、コレクションのどのプロパティを値として表示するかを指定することもできます。
DropDownList1.DataTextFiled="Name";
DropDownList1.DataValueField="id";
于 2013-09-07T05:49:20.390 に答える
0
drpdownlist の DropDownList1_SelectedIndexChanged イベントにコードを記述します。
if (DropDownList2.SelectedIndex == Convert.ToInt32(0))
{
your display code;
}
else if(DropDownList2.SelectedIndex == Convert.ToInt32(1))
{
your display code;
}
など... sqldatareader を使用して、Display records のレコードのリストを表示します
string qry="select * from your table name where youcolumforddl='" + DropDownList2.SelectedValue.ToString() + "'";
SqlCommand cmd = new SqlCommand(qry, yourconnection);
SqlDataReader dr=cmd.ExecuteReader();
if(dr.HasRows)
{
yourcontrols=dr[0].ToString();
....
....
if contorlis int type=Convert.ToInt32(dr[3]);
}
dr.Close();
cmd.Dispose();
于 2013-09-07T05:19:53.503 に答える
0
これを試して:
<asp:DropDownList ID="DropDownList1" runat="server" Width="128px" Height="32px" Style="position: relative;
top: 3px; left: 4px" >
<asp:ListItem>.......SELECT.......</asp:ListItem>
<asp:ListItem>Membership</asp:ListItem>
<asp:ListItem>Publication</asp:ListItem>
<asp:ListItem>Journal</asp:ListItem>
<asp:ListItem>Additional Activity</asp:ListItem>
<asp:ListItem>Guide Details</asp:ListItem>
<asp:ListItem>Project</asp:ListItem>
<asp:ListItem>Workshop</asp:ListItem>
</asp:DropDownList>
C#: ボタンクリックイベントで同じものを追加できます
protected void btnView_Click(object sender, EventArgs e)
{
if (DropDownList1.SelectedItem.Text == "Membership")// here you can add selectedindex as well
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionStringName"].ToString());
con.Open();
SqlDataAdapter adapter = new SqlDataAdapter("select columname from tablename where itemanme=Membership", con);
DataTable dt = new DataTable();
adapter.Fill(dt);
con.Close();
gridview1.DataSource=dt; // assign dt to the datasource of grid
gridview1.DataBind();
}
}
于 2013-09-07T05:50:27.350 に答える