在RowEditing事件上的GridView内部绑定DropDownList [英] Bind DropDownList Inside GridView On RowEditing Event

查看:166
本文介绍了在RowEditing事件上的GridView内部绑定DropDownList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

晚安朋友,

我正在开发一个应用程序,其中有一个包含gridview的页面,& gridview包含我想稍后编辑的下拉列表。数据成功绑定到rowcommand事件上的gridview。但是当我尝试绑定下拉列表时,在编排事件时,应用程序在编译时抛出错误。

错误是:

'系统。 Web.UI.Control'不包含'DataSource'的定义,并且没有可以找到接受类型'System.Web.UI.Control'的第一个参数的扩展方法'DataSource'(你是否缺少using指令或程序集参考?)



我被卡住了,请各位朋友帮帮我,任何建议都将不胜感激。

Good Evening Friends,
I am developing a application in which there is a page which contains gridview,& gridview contains dropdownlist which I want to edit later. The data is binding to gridview on rowcommand event successfully. but on rowediting event when I am trying to bind the dropdownlist the application is throwing error at compile time .
The Error Is:
'System.Web.UI.Control' does not contain a definition for 'DataSource' and no extension method 'DataSource' accepting a first argument of type 'System.Web.UI.Control' could be found (are you missing a using directive or an assembly reference?)

I am stuck ,please friends help me out of this, any suggestion will be appreciated.

推荐答案

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
   {
       GridView1.EditIndex = e.NewEditIndex;
       fill();
       DropDownList dl = (DropDownList)GridView1.Rows[e.NewEditIndex].FindControl("DropDownList1");
       dl.DataSource = li.selectMaritalLogic();
       dl.DataTextField = "marital_name";
       dl.DataValueField = "marital_id";
       dl.DataBind();
       CheckBoxList chk = (CheckBoxList)GridView1.Rows[e.NewEditIndex].FindControl("CheckBoxList1");
       chk.DataSource = li.selectHobbiesLogic();
       chk.DataTextField = "hobbies";
       chk.DataBind();
       RadioButtonList rb = (RadioButtonList)GridView1.Rows[e.NewEditIndex].FindControl("RadioButtonList1");
       rb.DataSource = li.selectgenderLogic();
       rb.DataTextField = "gender_id";
       rb.DataValueField = "name";
       rb.DataBind();
   }





这里我绑定网格编辑事件复选框列表,RadioButton和Dropdown



Here i am Binding ON Grid Editing Event Checkboxlist,RadioButton,and Dropdown


这篇关于在RowEditing事件上的GridView内部绑定DropDownList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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