我有一张桌子,有一张桌子 [英] i have a table, a drop down

查看:96
本文介绍了我有一张桌子,有一张桌子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表,一个下拉框和一个gridview控件.

当我从与表绑定的下拉框中选择一个项目时,我想在gridview中显示所有相关的列.

有人可以帮我吗?

I have a table, a dropdownbox, and a gridview control.

I want to display all the related columns in the gridview when I select an item from the dropdownbox that I have bounded with the table.

Can somebody help me?

推荐答案

让我们假设您有一个名为MyTable的表为(Column1,Column2,Column3)

您想将Column1值放在下拉列表中,并显示与所选Column1值相关的Column2和Column3值,对吗?

为此,假设您知道如何关联下拉列表和表格并将Column1值放入下拉列表的SelectedValue属性中,则可以执行以下操作,或者更好地使用StoredProcedure.

lets assume you have the table named MyTable as (Column1, Column2, Column3)

you want to put Column1 values in dropdown, and show the Column2 and Column3 values related to selected Column1 value, is that right?

for that, assuming you know how to relate dropdown and table and put the Column1 value into dropdown''s SelectedValue property, you can do as below, or better, use a StoredProcedure.

SqlCommand command = new SqlCommand()
{ 
   CommandText = string.Format("Select Column2, Column3 From MyTable Where Column1 = {0}", DropDown1.SelectedValue);
   Connection = new SqlConnection("Data Source=.;Initial Catalog={your database};Integrated Security=True");
   CommandType = CommandType.Text;
}

DataSet datasource = new DataSet();

using(SqlDataAdapter adapter = new SqlDataAdapter(command))
{
   adapter.Fill(datasource);
}



现在根据需要使用数据源,例如:



now use the datasource as you need, like :

GridView1.DataSoure = datasource.Tables[0];
GridView1.DataBind();



----------------------
问候

H.Maadani



----------------------
Regards

H.Maadani


这篇关于我有一张桌子,有一张桌子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆