如何为转发器内的复选框列表提供DataText字段,DataValue字段值 [英] How to give the DataText field ,DataValue field value for a checkbox list inside a repeater

查看:65
本文介绍了如何为转发器内的复选框列表提供DataText字段,DataValue字段值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在转发器控件中使用了一个checkboxlist。我正在绑定像这样的复选框列表



< asp:CheckBoxList ID =CheckBoxList1runat =serverDataSource ='<%#((系统。 Data.DataRowView)Container.DataItem).Row.GetChildRows(Child)%>'>



但是我无法使用datatext字段和Datavalue字段属性...如何给出这个。

解决方案

为Property取一个类。

  public   class  CheckBoxValues 
{
public string ValueToDisplay { get ; set ;}
public string ValueToBind { get ; set ;}
}



现在获取一个对象列表这个类和绑定此列表wi你的价值就像......

 ... 
List< checkboxvalues> ChkList = new List< checkboxvalues>();
// 获取类的新对象。
CheckBoxValues obj;
obj = new CheckBoxValues();
obj.ValueToDisplay = Cricket;
obj.ValueToBind = crick;
ChkList。 add (obj);
// 让我们添加另一个对象
obj = new CheckBoxValues();
obj.ValueToDisplay = Football;
obj.ValueToBind = ft;
ChkList。 add (obj);
// 您也可以动态添加。
...
// 现在将其作为复选框列表的文本字段和值字段。
chklistControll.DataSource = ChkList;
chklistControll.DataTextField = ValueToDisplay;
chklistControll.DataValueField = ValueToBind;
chklistControll.DataBind();





希望这个帮助

------ -----------

Pratik Bhuva


您好



以下链接可以帮助您。



http://stackoverflow.com/questions/13490548/to-to-set-text-of-checkbox-inside-repeater [ ^ ]



< a href =http://stackoverflow.com/questions/16170927/how-can-i-assign-an-id-to-a-checkbox-in-a-repeater> http://stackoverflow.com/questions / 16170927 / how-can-i-assign-an-id-to-a-checkbox-in-a-repeater [ ^ ]



如果它解决了您的问题,请将其标记为答案。


 <   asp:checkboxlist     runat   =  server    datatextfield   =  [ColumnName]    datavaluefield   =  [ColumnName]    /  >  


I am using a checkboxlist inside a repeater control. i am binding the checkbox list like this

<asp:CheckBoxList ID="CheckBoxList1" runat="server" DataSource='<%# ((System.Data.DataRowView)Container.DataItem).Row.GetChildRows("Child") %>' >

but i am not able to use the datatext field and Datavalue field property...How to give this.

解决方案

take a class for Property.

public class CheckBoxValues
{
   public string ValueToDisplay{get;set;}
   public string ValueToBind{get;set;}
}


Now Take a list of object of this class and bind this list with your value like...

...
List<checkboxvalues> ChkList =  new List<checkboxvalues>();
//take new object of class.
CheckBoxValues obj;
obj = new CheckBoxValues();
obj.ValueToDisplay = "Cricket";
obj.ValueToBind = "crick";
ChkList.add(obj);
//lets add another object
obj = new CheckBoxValues();
obj.ValueToDisplay = "Football";
obj.ValueToBind = "ft";
ChkList.add(obj);
//you can also add this dynamically.
...
//now give it as your checkBox list's textfield and valuefield.
chklistControll.DataSource = ChkList;
chklistControll.DataTextField = "ValueToDisplay";
chklistControll.DataValueField = "ValueToBind";
chklistControll.DataBind();



Hope This Help
-----------------
Pratik Bhuva


Hi

The following links may help you .

http://stackoverflow.com/questions/13490548/to-to-set-text-of-checkbox-inside-repeater[^]

http://stackoverflow.com/questions/16170927/how-can-i-assign-an-id-to-a-checkbox-in-a-repeater[^]

Please mark it as answer if it resolves your issue .


<asp:checkboxlist runat="server" datatextfield="[ColumnName]" datavaluefield="[ColumnName]" />


这篇关于如何为转发器内的复选框列表提供DataText字段,DataValue字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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