Results 1 to 2 of 2

Thread: Pls Help!!!!(Typecasting) <Resolved>

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Malaysia
    Posts
    345

    Pls Help!!!!(Typecasting) <Resolved>

    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>

    HTML Code:
    <asp:EditCommandColumn ButtonType="PushButton" UpdateText="Update" CancelText="Cancel" EditText="Edit Info"></asp:EditCommandColumn>
    <asp:ButtonColumn Text="Delete" CommandName="Delete"></asp:ButtonColumn>
    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.

    This is the entire code of ny datagrid.

    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>
    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)

    Code:
    string strName;
    TextBox aTextBox;
    aTextBox = (TextBox)(e.Item.Cells[1].Controls[0]);
    strName = aTextBox.Text;
    HOWEVER MY PROBLEM IS WHILE TYPECASTING MY CHECKBOX

    Code:
    cb= (CheckBox)(e.Item.Cells[5].Controls[0]);
    
    OR
    
    cb = (CheckBox)(e.Item.FindControl("chkActive"));
    I GET AN ERROR:

    Specified cast is not valid.

    I am going mad..pls help.
    Last edited by sinha; Jun 7th, 2005 at 11:03 AM.
    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width