Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Helo..
I m new to asp.net..I m making crystal reports,in which i have to bind chekbox in gridview..i m not able to do coding..I have return the following code in my .aspx form.bt its throwing me error for checked property.plz help me.

ASP.NET
<asp:GridView ID="GridView1" runat="server"
            AutoGenerateColumns="False">
            <Columns>
                <asp:TemplateField HeaderText="StaffName">
                <ItemTemplate>

                    <asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Eval("StaffName") %>' /></ItemTemplate>
                    <HeaderStyle CssClass="grdheadermster" />
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
Posted
Updated 7-Sep-12 19:48pm
v2

hiii,
if your staffname is string then do one more thing

XML
<asp:templatefield>
  <itemtemplate>
  <asp:checkbox id="chkOnlineCheck" runat="server" checked="<%# Eval("staffname").ToString() == "sample" ? false : true) %>" />' />
  </itemtemplate>
</asp:templatefield>



where replace follwing condition by your own

Eval("staffname").ToString() == "sample"
 
Share this answer
 
Hi ,
Check this
C#
protected void Page_Load(object sender, EventArgs e)
  {
      if (!IsPostBack)
      {
          GridView1.DataSource = GetData();
          GridView1.DataBind();
      }

  }
  DataTable GetData()
  {
      DataTable dt = new DataTable();
      using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString))
      {
          con.Open();
          using (SqlCommand cmd = new SqlCommand("select productid ,flag from product ", con))
          {

              SqlDataAdapter adpt = new SqlDataAdapter(cmd);
              adpt.Fill(dt);
          }

      }
      return dt;
  }

XML
<div>

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
        <Columns>
            <asp:TemplateField HeaderText="id">
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text="<%# Bind('id') %>"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Check">
                <ItemTemplate>
                    <asp:CheckBox ID="CheckBox1" runat="server" Checked="<%# Bind('flag') %>" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

</div>


Best Regards
M.Mitwalli
 
Share this answer
 
Comments
__TR__ 8-Sep-12 4:41am    
5ed!
Mohamed Mitwalli 8-Sep-12 4:48am    
Thanks TR :)
Aysha Patel 26-Sep-12 1:15am    
Thanks a lot mohamed...
Mohamed Mitwalli 26-Sep-12 1:24am    
Your welcome Aysha :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900