0
我創建一個空的數據行到我的網格視圖結合,但是,我一直都想與「指定的強制轉換無效」錯誤消息對我的複選框複選框指定的轉換無效
這是我的aspx:
<asp:TemplateField HeaderText="Include In Food Bag" ItemStyle-Width="20%" ItemStyle-HorizontalAlign="Center" FooterStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox runat="server" ID="ChkBxIncludeInFoodBag" Checked='<%# Bind("IncludeInFoodBag") %>' ></asp:CheckBox>
</ItemTemplate>
<FooterTemplate>
<asp:CheckBox runat="server" ID="ChkBxIncludeInFoodBag"></asp:CheckBox>
</FooterTemplate>
</asp:TemplateField>
這是我的代碼背後:
protected void BindFoodBagItemsGridView()
{
DataTable FoodBagItems = BLFoodBagItem.GetAllFoodBagItems();
if (FoodBagItems.Rows.Count > 0)
{
FoodBagItemsGridView.DataSource = BLFoodBagItem.GetAllFoodBagItems();
}
else
{
tempFoodItems = new DataTable();
tempFoodItems.Columns.Add("FoodBagItemId");
tempFoodItems.Columns.Add("ItemName");
tempFoodItems.Columns.Add("ItemQuantity");
tempFoodItems.Columns.Add("IncludeInFoodBag");
DataRow dr = tempFoodItems.NewRow();
dr["IncludeInFoodBag"] = bool.Parse("false");
-- I also tried dr["IncludeInFoodBag"] = false;
-- I also tried dr["IncludeInFoodBag"] = 0;
tempFoodItems.Rows.Add(dr);
FoodBagItemsGridView.DataSource = tempFoodItems;
}
FoodBagItemsGridView.DataBind();
}