Checkbox checked inside asp.net GridView

I have a asp.net grid view and i have IsActive field in database and it comes as 1 or 0.So i need according to that value Grid view Checkbox is checked or not.

Grid View Field

<asp:TemplateField>
            <ItemTemplate>
                <asp:CheckBox ID="chkIsActive" DataField="ISACTIVE" HeaderText="Is Active"  runat="server" Checked='<%# Eval("ISACTIVE") %>'/>

            </ItemTemplate>
        </asp:TemplateField>

Code Behind

 GridRes gridRes = NewsProxy.GetAllnews(req);
            gv.DataSource = gridRes.Dataset;
            gv.DataBind();

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

If your IsActive field is a bit column and contains only 0 or 1 then you can do like below in order to pre-check or unchech the checkbox.

<asp:CheckBox ID="chkIsActive" DataField="ISACTIVE" HeaderText="Is Active"  runat="server" Checked='<%# Convert.ToBoolean(Eval("ISACTIVE")) %>'/>


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x