填充DropDownList的一个gridview里面

填充DropDownList的一个gridview里面

本文介绍了填充DropDownList的一个gridview里面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个GridView一个DropDownList,我必须表现出与每一个相关的id.And ID包含超过10条记录,所以我怎么能告诉他们??记录

 保护无效GridView1_RowDataBound(对象发件人,GridViewRowEventArgs E)
        {
            如果(e.Row.RowType == DataControlRowType.DataRow)
            {
                con.Open();
                VAR DDL =(DropDownList的)e.Row.FindControl(DropDownList1);
                // INT CountryId = Convert.ToInt32(e.Row.Cells [0]。文本);
                CMD的SqlCommand =新的SqlCommand(选择姓氏从Profile_MasterCON);
                SqlDataAdapter的大=新SqlDataAdapter的(CMD);
                DataSet的DS =新的DataSet();
                da.Fill(DS);
                con.Close();
                ddl.DataSource = DS;
                ddl.DataTextField =姓氏;
                ddl.DataBind();            }
        }


解决方案

我们只是碰到了这个问题,我的工作。我们解决这个问题的办法是首先获得DropDownLists的UniqueID。这基本上是一个客户端ID。里面那个ID的是,它是从选定在GridView的行的引用。唯一的问题是,它似乎增加2到行计数。所以,如果你选择第1行的DROPDOWNLIST,独特的ID将带您到第三排的参考。所以:

获取的唯一ID>但是拆分它,你需要让行>使用行数来获得你所需要的值。

I have a Dropdownlist in a Gridview and i have to show the records associated with every id.And the ID contains more than 10 records so how can i show them??

 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                con.Open();
                var ddl = (DropDownList)e.Row.FindControl("DropDownList1");
                //int CountryId = Convert.ToInt32(e.Row.Cells[0].Text);
                SqlCommand cmd = new SqlCommand("select LastName from Profile_Master",        con);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                da.Fill(ds);
                con.Close();
                ddl.DataSource = ds;
                ddl.DataTextField = "LastName";
                ddl.DataBind();

            }
        }
解决方案

We just ran into this issue where I work. Our way around this problem was to first get the DropDownLists UniqueID. This is basically a Client ID. Inside of that ID is a reference to the row of the GridView that it was selected from. THE ONLY PROBLEM is that it seems to add 2 to the row count. So if you select Row 1's DropdownList, the Unique ID will bring you a reference to the 3rd row. So:

Get the unique ID > Split it however you need to to get the row > use the row number to get the values you need.

这篇关于填充DropDownList的一个gridview里面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 12:44