如何使用Eval()将数据源的值绑定到数据列表中的复选框 [英] how to bind a value of datasource to a checkbox in datalist with Eval()
本文介绍了如何使用Eval()将数据源的值绑定到数据列表中的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的asp.net页面上有一个数据列表。我将数据源绑定到
后面的代码中,并且在此数据列表中有一个复选框。
I have a datalist in my asp.net page. I bind a datasource to it in codebehind and I have a checkbox in this datalist.
var n = from gi in DataContext.Context.GalleryImages
join g in DataContext.Context.Galleries
on gi.GalleryID equals g.GalleryID
where g.UserID == UserID && gi.GalleryID==GalleryID
select new
{
GalleryID = g.GalleryID,
ImageDescription = gi.ImageDescription,
GalleryName = g.GalleryName,
ImageFileName = gi.ImageFileName,
IsAlbumImage = gi.IsAlbumImage,
ImageID=gi.ImageID
};
dlGalleryList.DataSource = n;
dlGalleryList.DataBind();
当 IsAlbumImage为true时,应选中该复选框。
如何将该属性绑定到复选框?
When the "IsAlbumImage " is true the checkbox should be checked. How can I bind this property to the checkbox?
推荐答案
就像这样:
<asp:CheckBox
ID="check"
runat="server"
Checked='<%# Eval("column_name").ToString().Equals("1") %>'
/>
这篇关于如何使用Eval()将数据源的值绑定到数据列表中的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文