二:托动一个GridView到页面,设置数据源.
三.托动一个DropList
如图
其中DropDownList1代码: 记住DropDownList1控件一定要设置AutoPostBack为true,不然就不能显示正常的结果,我当时也没有这么做,害我找了好久错在哪儿,笨啊!
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
for (int i = 1; i <= GridView1.Columns .Count ; i++)
DropDownList1.Items.Add(i.ToString());//填充数据为表列数
}
}
双击隐藏列和显示列按扭进处代码编辑:
protected void Button1_Click(object sender, EventArgs e)
{
int columns = Convert.ToInt32(DropDownList1 .SelectedValue)-1;//选中的列数字
GridView1 .Columns [columns ].Visible =false ; //使列隐藏
}
protected void Button2_Click(object sender, EventArgs e)
{
int cn = Convert.ToInt32(DropDownList1 .SelectedValue)-1;
if (GridView1.Columns[cn].Visible == false)//假如没有显示该列则显示
GridView1.Columns[cn].Visible = true;
}