Hi!
I have bound my data grid to a table made in MS Access Database.
I am doing Edit and Delete in the Datagrid only. For that I am using
<asp:EditCommandColumn button>
In the datagrid I have a colums which displays a checkbox. It is checked if the column in the database has 'true' value and vice versa.HTML Code:<asp:EditCommandColumn ButtonType="PushButton" UpdateText="Update" CancelText="Cancel" EditText="Edit Info"></asp:EditCommandColumn> <asp:ButtonColumn Text="Delete" CommandName="Delete"></asp:ButtonColumn>
This is the entire code of ny datagrid.
Now while writing the update code on the dgCompany_UpdateCommand, I am typecasting the values in my text box (which I get on clicking the edit button)HTML Code:<asp:datagrid id="dgCompany" runat="server" BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellSpacing="1" BackColor="White" CellPadding="3" GridLines="None" Height="322px" AllowSorting="True" AutoGenerateColumns="False" AllowPaging="True" OnEditCommand="dgCompany_EditCommand" OnDeleteCommand="dgCompany_DeleteCommand" OnCancelCommand="dgCompany_CancelCommand" OnUpdateCommand="dgCompany_UpdateCommand"> <FooterStyle ForeColor="Black" CssClass="DataGrid_FooterStyle" BackColor="#C6C3C6"></FooterStyle> <SelectedItemStyle Font-Bold="True" ForeColor="White" CssClass="DataGrid_SelectedItemStyle" BackColor="#9471DE"></SelectedItemStyle> <AlternatingItemStyle CssClass="DataGrid_AlternatingItemStyle"></AlternatingItemStyle> <ItemStyle ForeColor="Black" CssClass="DataGrid_ItemStyle" BackColor="#DEDFDE"></ItemStyle> <HeaderStyle Font-Bold="True" ForeColor="#E7E7FF" CssClass="DataGrid_HeaderStyle" BackColor="#4A3C8C"></HeaderStyle> <Columns> <asp:BoundColumn DataField="UserID" SortExpression="UserID" ReadOnly="True" HeaderText="User ID"></asp:BoundColumn> <asp:BoundColumn DataField="Name" SortExpression="Name" HeaderText="Name"></asp:BoundColumn> <asp:BoundColumn DataField="Company" SortExpression="Company" HeaderText="Company"></asp:BoundColumn> <asp:BoundColumn DataField="Email" SortExpression="Email" HeaderText="Email"></asp:BoundColumn> <asp:TemplateColumn HeaderText="Active"> <HeaderStyle HorizontalAlign="Center"></HeaderStyle> <ItemTemplate> <input type="checkbox" runat="server" id="chkActive" checked='<%#DataBinder.Eval(Container.DataItem, "ACTIVE") %>'/> </ItemTemplate> </asp:TemplateColumn> <asp:EditCommandColumn ButtonType="PushButton" UpdateText="Update" CancelText="Cancel" EditText="Edit Info"></asp:EditCommandColumn> <asp:ButtonColumn Text="Delete" CommandName="Delete"></asp:ButtonColumn> </Columns> <PagerStyle HorizontalAlign="Right" ForeColor="Black" BackColor="#C6C3C6"></PagerStyle> </asp:datagrid>
HOWEVER MY PROBLEM IS WHILE TYPECASTING MY CHECKBOXCode:string strName; TextBox aTextBox; aTextBox = (TextBox)(e.Item.Cells[1].Controls[0]); strName = aTextBox.Text;
I GET AN ERROR:Code:cb= (CheckBox)(e.Item.Cells[5].Controls[0]); OR cb = (CheckBox)(e.Item.FindControl("chkActive"));
Specified cast is not valid.
I am going mad..pls help.




Reply With Quote