如何将下拉列表中的选择值显示到gridview中 [英] how to display select value from dropdown list into gridview

查看:147
本文介绍了如何将下拉列表中的选择值显示到gridview中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个asp.net下拉列表和1个按钮



dropdownlist1 =(项目编号)



dropdownlist2 =(项目名称)



dropdownlist3 =(活动)



button =(add)



(关于您的信息:我在Sharepoint2010中调用列表中的下拉值)



我选择的项目数字,

然后我选择标题然后活动...

按添加按钮然后在gridview中显示所有值。





问题是,当数据插入到gridview行时,它将逐行拉伸网格视图而不是html表。



如何在html表中逐行插入?

I have 3 asp.net dropdownlist and 1 Button

dropdownlist1=(project number)

dropdownlist2=(project title)

dropdownlist3=(activity)

button =(add)

(for your info : I call the value of dropdown from list in Sharepoint2010)

I selected project number,
then I select title then activity...
press add button then all value displayed in gridview.


The problem is ,when data was insert to gridview row, it will stretch the gridview down not in html table row by row.

How to inserted it row by row in html table?

推荐答案

这里我开发了以下代码

Here I have Developed following code
static DataTable dt;
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        dt = new DataTable();
        dt.Columns.Add("Project Number");
        dt.Columns.Add("Title");
        dt.Columns.Add("Activity");
    }
    GridView1.DataSource = dt;
    GridView1.DataBind();
}

protected void Button1_Click(object sender, EventArgs e)
{
    DataRow dr = dt.NewRow();
    dr[0] =  DropDownList1.SelectedValue;
    dr[1] =  DropDownList2.SelectedValue;
    dr[2] =  DropDownList3.SelectedValue;
    dt.Rows.Add(dr);
    GridView1.DataSource = dt;
    GridView1.DataBind();
}





我希望这会对你有所帮助



I hope this will be helpful to you


尝试级联下拉菜单 -

http://www.asp.net/ajaxLibrary /AjaxControlToolkitSampleSite/CascadingDropDown/CascadingDropDown.aspx [ ^ ]

http://www.asp.net/ ajaxLibrary / AjaxControlToolkitSampleSite / Walkthrough / CCDWithDB.aspx [ ^ ]

http://code.msdn.microsoft.com/CSASPNETCascadingDropDownLi -0 a3f1ecf [ ^ ]
Try cascading dropdowns -
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/CascadingDropDown/CascadingDropDown.aspx[^]
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/Walkthrough/CCDWithDB.aspx[^]
http://code.msdn.microsoft.com/CSASPNETCascadingDropDownLi-0a3f1ecf[^]


请按照以下示例:



Follow this example:

Protected Sub btnSaveEmail_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSaveEmail.Click
        dt_email = Session("dt_email") 'OR Dim dt_email As New DataTable

        Dim dr As DataRow
        dr = dt_email.NewRow()

        dr("intCodigoClienteEmail") = Cint(DropDownList.Selectedvalue)
        dr("intCodigoCliente") = Cint(DropDownList.Selectedvalue)
        dr("vchEmail") = Cint(DropDownList.Selectedvalue)

        dt_email.Rows.Add(dr)

        grdEmail.DataSource = dt_email
        grdEmail.DataBind()

        Session("dt_email") = dt_email
    End Sub







首先,您可以创建一个数据表,或者可以创建一个新的数据表,然后通过添加一行作为所选值来创建数据表DataRow。

毕竟完成后,使用datarow加载数据表。

之后加载带有数据表的网格




First you take a datatable existing OR can create a new one, then create a datatable DataRow this by adding a line as the selected values​​.
After all done, load the datatable with the datarow.
After that load the grid with datatable


这篇关于如何将下拉列表中的选择值显示到gridview中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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