asp.net的gridview中的复选框 [英] checkboxes in gridview of asp.net

查看:74
本文介绍了asp.net的gridview中的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在asp.net的网格视图中使用具有非布尔值的复选框

我已经使用itemtemplate创建了复选框,但是当我尝试使用sql表将整数值绑定到浏览器时,它在浏览器上创建了错误.
请提出一些建议.

how to use checkboxes in grid view in asp.net with integer values not boolean

i have created checkboxes by using itemtemplate but it creates error on browser when i try to bind integer values to it using my sql table.

pls suggest something

推荐答案

您遇到什么错误?您要与该字段绑定的数据类型是什么?如果您是一个布尔值,并且希望将其绑定到CheckBox中,则无需这样做,因为GridView会自动处理所有这些问题.布尔值仅在CheckBox中呈现.
对于绑定任何其他值",您可以在aspx页中或在后面的代码中使用该数据字段的绑定表达式.
What error are you getting ? What is the Data Type that you are binding with that field ? If you it''s a Boolean value and you want to bind it in CheckBox, there is no need, as GridView Automatically Takes care of all these. Boolean values renders in to CheckBox Only.
For Binding any other value, you can either use bind expression of that data field in aspx pages or in code Behind.
<asp:GridView ID="GridView1" runat="server">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:checkbox id="CheckBoxid" runat="server" xmlns:asp="#unknown">
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView></asp:checkbox>



在RowDataBound期间,从后面的代码中,您可以按以下方式访问它



From the code behind, during RowDataBound, you can access it as below

protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
YourClass object = (YourClass)e.Row.DataItem;
CheckBox chkbox = e.Row.FindControl("CheckBoxid");
chkbox.Text = object.someProperties. 
}
}



希望这会有所帮助!



Hope this will help !


这篇关于asp.net的gridview中的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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