我想使用c#在asp.net中将列表框项显示到gridview中 [英] i want to display the Listbox items into gridview in asp.net using c#

查看:74
本文介绍了我想使用c#在asp.net中将列表框项显示到gridview中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Listbox1如下



部门

HR

账户

IT

接待



Listbox2如下



Deparment incharge

Ram

Sam

Raj

Suresh





在页面加载中我想在Gridview中显示Listbox1和Listbox2项目。



在Gridview中我想要输出如下



部门部门负责人



HR Ram

账户Sam

IT Raj

接待Suresh





我怎样才能在asp.net中使用c#。



问候,

Narasiman P

Listbox1 as follows

Department
HR
Accounts
IT
Reception

Listbox2 as follows

Deparment incharge
Ram
Sam
Raj
Suresh


In page load i want to display the Listbox1 and Listbox2 items in Gridview.

In Gridview i want output as follows

Department Deparment incharge

HR Ram
Accounts Sam
IT Raj
Reception Suresh


for that how can i do in asp.net using c#.

Regards,
Narasiman P

推荐答案

试试这样..





Try like this..


protected void btn_Click(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("Department", typeof(string));
            dt.Columns.Add("Name", typeof(string));

            if (ListBox1.Items.Count == ListBox2.Items.Count)
            {
                for (int i = 0; i < ListBox1.Items.Count; i++)
                {
                    dt.Rows.Add(ListBox1.Items[i].Text, ListBox2.Items[i].Text);
                }
                gridview.DataSource = dt;
                gridview.DataBind();

            }
        }


这篇关于我想使用c#在asp.net中将列表框项显示到gridview中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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