在gridview中为dropedownlist设置数据源以获取另一个表的数据 [英] set datasource for dropedownlist in gridview for another table's data

查看:61
本文介绍了在gridview中为dropedownlist设置数据源以获取另一个表的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在页面加载时从asp.net中的另一个表将数据源设置为gridview的dropdownlist中的c#

how to set datasource to dropdownlist in gridview at page load from another table in asp.net c#

推荐答案

如果页脚中存在下拉菜单,则更好RowDataBound,

If you have dropdown in footer means better to go for RowDataBound,

protected void gvBindDropDown_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            DropDownList dropDownList = e.Row.FindControl("dropDownListID") as DropDownList;
            dropDownList.DataSource = dtDropDownData;  //Datatable 
            dropDownList.DataTextField = "Description";
            dropDownList.DataValueField = "Value";
            dropDownList.DataBind();
            dropDownList.Items.Insert(0, new ListItem("-Select-", "0"));
        }
    }



如果存在,则行表示使用



if it is there Row means use

if (e.Row.RowType == DataControlRowType.DataRow)
{
    //Bind drop down..
}



希望对您有帮助.



Hope this will help you..


在方法更改后的Filling gridview调用后,您好
grdSetData这是我的gridview的名称,而不是这个yr的网格名称

Hi after Filling gridview call below method change Accordingly
grdSetData this is name of my gridview instead this put yr grid name

protected void fillDropDown(DataTable dt)
   {
       foreach (GridViewRow grdRow in grdSetData.Rows)
       {
           DropDownList ddl = (DropDownList)(grdSetData.Rows[grdRow.RowIndex].Cells[0].FindControl(ddlEmpName));
           ddl.DataSource = dt;
           ddl.DataValueField = Salary;
           ddl.DataTextField = empName;
           ddl.DataBind();
       }
   }


这篇关于在gridview中为dropedownlist设置数据源以获取另一个表的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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