I bind the Gridview with SQL. I have one bit data type column in SQL table.
I want to have one checkbox type column in Gridview. My code is working if database have true or false in all rows. But if the row contains NULL, my code doesn't work. Help me in Modifying the code.
SOURCE CODE : -
SERVER SIDE CODE : -Code:<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns ="false"> <Columns > <asp:BoundField DataField="Question_ID" HeaderText="Ques ID :" /> <asp:TemplateField > <ItemTemplate > <asp:CheckBox ID="chkbox" Checked='<%#Convert.ToBoolean(Eval("Active")) %>' runat ="server" /> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>
ERROR : -Object cannot be cast from DBNull to other types.Code:protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { query = "Select * from INSERT_QUESTION"; cmd = new SqlCommand(query, con); cmd.CommandType = CommandType.Text; da = new SqlDataAdapter(cmd); da.Fill(ds); GridView1.DataSource = ds; GridView1.DataBind(); } }


Reply With Quote

