如何将下拉列表的值绑定到gridview [英] How to bind the values of dropdown into gridview

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

问题描述



我想将下拉列表中选择的值绑定到gridview中,以供gridview中的选定值使用.在我的应用程序中,我使用的是gridview,其中有5列和1列带有复选框,在这里我将选中此复选框,并且当我在下拉列表中选择值并单击Submit按钮时,我在gridview之外有一个下拉列表,则下拉列表中的值应绑定到选中的复选框行.谁能帮我解决这个问题.

在此先感谢

Hi,

I want to bind the values that are selected in the dropdown into the gridview for the selected vales in the gridview. In my application I am using the gridview in that there are 5 columns and one column with check box, here I will select this check box and i am having an dropdown outside the gridview when I select the values in the dropdown and click the submit button, the values in the dropdown should be binded to selected checkbox row. Can any one help me to solve this issue.

Thanks in Advance

推荐答案

GridViewRow row = GridView1.Rows[e.RowIndex];
       string eno;

       eno = GridView1.DataKeys[e.RowIndex].Value.ToString();

       TextBox empname = (TextBox)row.FindControl("txtempname");
       DropDownList status = (DropDownList)row.FindControl("DropDownList1");
       string selval;

       if (status.SelectedValue == "Yes")
       {
           selval = "Y";
       }
       else
       {
           selval = "N";
       }

       sqlcon.Open();
       sqlcmd = new SqlCommand("update emp set empname=''" + empname.Text + "'',empstatus=''" + selval + "'' where eno=''" + eno + "''",sqlcon);
       sqlcmd.CommandType = CommandType.Text;
       sqlcmd.ExecuteNonQuery();
       sqlcon.Close();
       GridView1.EditIndex = -1;
       GridData();







选中此链接







check this link


使用变量selectedValue作为查询的输入参数.

Use the variable selectedValue as input paramater to your query.

string selectedValue = ddlCategory.SelectedValue;



我知道您可以自己进行查询:)

如果可以解决您的问题,请将其标记为正确答案

最好的问候.
爱德华



I know you can do the query yourself :)

Mark this as correct answer if it solves your problem

Best regards.
Eduard


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

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