Datagridview edit row with checkbox

Discussion in 'ASP .Net' started by rgparkins, Oct 5, 2007.

  1. rgparkins

    rgparkins Guest

    HI I am struggling with this one and its got to be a simple solution.
    I have 3 columns in a datagridview the 4th being the edit/delete
    buttons for that row, when I click the edit button I have the
    following:

    column 1 is a textbox
    column 2 is a checkbox
    column 3 is a dropdownlist

    When I do an update the only column that is updated is the textbox,
    the other 2 dont pass the new value I have selected to the update
    method on the objectdatasource. Could anyone throw me a lifeline, I am
    using .NET 2.0

    I have checked at the db and yes the only one that is updated is the
    textbox so its not a binding issue after the update.

    Many thanks

    Richard
    rgparkins, Oct 5, 2007
    #1
    1. Advertising

  2. rgparkins

    Kbalz Guest

    On Oct 5, 6:42 am, rgparkins <> wrote:
    > HI I am struggling with this one and its got to be a simple solution.
    > I have 3 columns in a datagridview the 4th being the edit/delete
    > buttons for that row, when I click the edit button I have the
    > following:
    >
    > column 1 is a textbox
    > column 2 is a checkbox
    > column 3 is a dropdownlist
    >
    > When I do an update the only column that is updated is the textbox,
    > the other 2 dont pass the new value I have selected to the update
    > method on the objectdatasource. Could anyone throw me a lifeline, I am
    > using .NET 2.0
    >
    > I have checked at the db and yes the only one that is updated is the
    > textbox so its not a binding issue after the update.
    >
    > Many thanks
    >
    > Richard


    Can you post all of the gridview's related code, and datasource's code
    (like updatestatements).
    Kbalz, Oct 5, 2007
    #2
    1. Advertising

  3. rgparkins

    rgparkins Guest

    Hi Kbatz

    As requested, many thanks, the objectdatasource calls the background
    routine here:

    /// <summary>
    /// UPdate product detail
    /// </summary>
    /// <returns></returns>
    public static void UpdateProduct(long PId, string PCostString,
    string PDescription, decimal PGross, bool PSpecial, int PStatus, bool
    PBillable, string PSupplimentary1) ;


    Many thanks

    Rich

    <asp:GridView ID="GridViewDetail" DataSourceID="ObjectDataSource1"
    runat="server" AutoGenerateColumns="False"
    DataKeyNames="PId,PSpecial,PBillable,PStatus" PageSize="100"
    OnRowDataBound="GridViewDetail_RowDataBound" ShowFooter="True"
    OnRowCommand="GridViewDetail_RowCommand"
    OnRowUpdating="GridViewDetail_RowUpdating"
    CssClass="subcostsfullspan">
    <Columns>
    <asp:TemplateField>
    <ItemTemplate>
    <asp:Button Text="Edit" CommandName="Edit"
    CausesValidation="false" runat="server" ID="btEdit" />&nbsp;
    <asp:Button Text="Delete" CommandName="Delete"
    CausesValidation="false" runat="server" ID="btDelete" />
    </ItemTemplate>
    <EditItemTemplate>
    <asp:Button Text="Update" CommandName="Update"
    CausesValidation="false" runat="server" ID="btUpdate" />&nbsp;
    <asp:Button Text="Cancel" CommandName="Cancel"
    CausesValidation="false" runat="server" ID="btCancel" />
    </EditItemTemplate>
    <FooterTemplate>
    <asp:Button Text="Insert" CommandName="Insert"
    CausesValidation="true" runat="server" ID="btInsert" />
    </FooterTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Description">
    <EditItemTemplate>
    <asp:TextBox ID="TextBoxGridDescription"
    runat="server" Text='<%# Bind("PDescription") %>'></asp:TextBox>
    </EditItemTemplate>
    <ItemTemplate>
    <asp:Label ID="LabelDescription" runat="server"
    Text='<%# Bind("PDescription") %>'></asp:Label>
    </ItemTemplate>
    <FooterTemplate>
    <asp:TextBox ID="TextBoxGridDescriptionInsert"
    runat="server"></asp:TextBox>
    </FooterTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Cost (£)">
    <EditItemTemplate>
    <asp:TextBox ID="TextBoxGridGross" runat="server"
    Text='<%# Bind("PGross") %>' CssClass="subcostsfullspantxtbox"></
    asp:TextBox>
    </EditItemTemplate>
    <ItemTemplate>
    <asp:Label ID="LabelGross" runat="server" Text='<
    %# Bind("PGross") %>'></asp:Label>
    </ItemTemplate>
    <FooterTemplate>
    <asp:TextBox ID="TextBoxGridGrossInsert"
    runat="server" CssClass="subcostsfullspantxtbox"></asp:TextBox>
    </FooterTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Cost string">
    <EditItemTemplate>
    <asp:TextBox ID="TextBoxGridCostString"
    runat="server" Text='<%# Bind("PCostString") %>'></asp:TextBox>
    </EditItemTemplate>
    <ItemTemplate>
    <asp:Label ID="LabelCostString" runat="server"
    Text='<%# Bind("PCostString") %>'></asp:Label>
    </ItemTemplate>
    <FooterTemplate>
    <asp:TextBox ID="TextBoxGridCostStringInsert"
    runat="server" CssClass="subcostsfullspantxtbox"></asp:TextBox>
    </FooterTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Special">
    <EditItemTemplate>
    <asp:CheckBox ID="CheckBoxGridSpecial"
    runat="server" Checked='<%# Bind("PSpecial")%>'></asp:CheckBox>
    </EditItemTemplate>
    <ItemTemplate>
    <asp:Label ID="LabelSpecial" runat="server" Text='<
    %# Bind("PSpecial") %>'></asp:Label>
    </ItemTemplate>
    <FooterTemplate>
    <asp:CheckBox ID="CheckBoxGridSpecialInsert"
    runat="server"></asp:CheckBox>
    </FooterTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Billable">
    <EditItemTemplate>
    <asp:CheckBox ID="CheckBoxGridBillable"
    runat="server" Checked='<%# Bind("PBillable")%>'></asp:CheckBox>
    </EditItemTemplate>
    <ItemTemplate>
    <asp:Label ID="LabelBillable" runat="server"
    Text='<%# Bind("PBillable") %>'></asp:Label>
    </ItemTemplate>
    <FooterTemplate>
    <asp:CheckBox ID="CheckBoxGridBillableInsert"
    runat="server"></asp:CheckBox>
    </FooterTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Status">
    <EditItemTemplate>
    <asp:DropDownList ID="DropDownListGridStatus"
    runat="server">
    <asp:ListItem Value="1" Text="For Sale"></
    asp:ListItem>
    <asp:ListItem Value="2" Text="On Hold"></
    asp:ListItem>
    <asp:ListItem Value="3" Text="Sold"></
    asp:ListItem>
    </asp:DropDownList>
    </EditItemTemplate>
    <ItemTemplate>
    <asp:Label ID="LabelStatus" runat="server" Text='<
    %# Bind("PStatus") %>'></asp:Label>
    </ItemTemplate>

    <FooterTemplate>
    <asp:DropDownList
    ID="DropDownListGridStatusInsert" runat="server">
    <asp:ListItem Value="1" Text="For Sale"></
    asp:ListItem>
    <asp:ListItem Value="2" Text="On Hold"></
    asp:ListItem>
    <asp:ListItem Value="3" Text="Sold"></
    asp:ListItem>
    </asp:DropDownList>
    </FooterTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="# Rooms" Visible="False">
    <EditItemTemplate>
    <asp:TextBox ID="TextBoxGridSupplimentary1"
    runat="server" Text='<%# Bind("PSupplimentary1") %>'></asp:TextBox>
    </EditItemTemplate>
    <ItemTemplate>
    <asp:Label ID="LabelTextBoxGridSupplimentary1"
    runat="server" Text='<%# Bind("PSupplimentary1") %>'></asp:Label>
    </ItemTemplate>
    <FooterTemplate>
    <asp:TextBox ID="TextBoxGridSupplimentary1Insert"
    runat="server" CssClass="subcostsfullspantxtbox"></asp:TextBox>
    </FooterTemplate>
    </asp:TemplateField>

    </Columns>
    <EmptyDataTemplate>
    <table border="0" width="100%" cellspacing="0"
    cellpadding="0">
    <tr>
    <td class="heading">Description:</td>
    <td><asp:TextBox
    ID="TextBoxGridDescriptionInsertEmpty" runat="server"
    CssClass="inpvariants"></asp:TextBox></td>
    </tr>
    <tr>
    <td class="heading">Gross:</td>
    <td><asp:TextBox ID="TextBoxGridGrossInsertEmpty"
    runat="server" CssClass="inpvariants"></asp:TextBox></td>
    </tr>
    <tr>
    <td class="heading">CostString:</td>
    <td><asp:TextBox ID="TextBoxGridCostStringInsertEmpty"
    runat="server" CssClass="inpvariants"></asp:TextBox></td>
    </tr>
    <tr>
    <td class="heading">Special:</td>
    <td><asp:CheckBox ID="CheckBoxGridSpecialInsertEmpty"
    runat="server"></asp:CheckBox></td>
    </tr>
    <tr>
    <td class="heading">Billable:</td>
    <td><asp:CheckBox ID="CheckBoxGridBillableInsertEmpty"
    runat="server"></asp:CheckBox></td>
    </tr>
    <tr>
    <td class="heading">Status:</td>
    <td><asp:DropDownList
    ID="DropDownListGridStatusInsertEmpty" runat="server"
    CssClass="inpvariants">
    <asp:ListItem Value="1" Text="For Sale"></
    asp:ListItem>
    <asp:ListItem Value="2" Text="On Hold"></
    asp:ListItem>
    <asp:ListItem Value="3" Text="Sold"></
    asp:ListItem>
    </asp:DropDownList></td>
    </tr>
    <tr>
    <td class="heading"><asp:Label
    ID="LabelSupplimentary1" runat="server" Text="Supplimentary"></
    asp:Label>:</td>
    <td><asp:TextBox ID="TextBoxGridSupplimentary1Empty"
    runat="server" CssClass="inpvariants"></asp:TextBox></td>
    </tr>
    <tr>
    <td colspan="2" align="right"><asp:Button ID="btSend"
    Text="Insert" runat="server" CommandName="EmptyInsert"
    UseSubmitBehavior="False" /></td>
    </tr>
    </table>
    </EmptyDataTemplate>
    </asp:GridView>
    &nbsp;
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
    SelectMethod="GetProductsByCategory"

    TypeName="SurbitonPlaza.LifeStyleSystem.BusinessLayer.Search.ProductManager"
    UpdateMethod="UpdateProduct" DeleteMethod="DeleteProduct"
    OnDeleting="ObjectDataSource1_Deleting"
    OnUpdating="ObjectDataSource1_Updating">
    <UpdateParameters>
    <asp:parameter Name="PId" Type="Int64" />
    <asp:parameter Name="PCostString" Type="String" />
    <asp:parameter Name="PDescription" Type="String" />
    <asp:parameter Name="PGross" Type="Decimal" />
    <asp:parameter Name="PSpecial" Type="Boolean" />
    <asp:parameter Name="PStatus" Type="Int32" />
    <asp:parameter Name="PBillable" Type="Boolean" />
    <asp:parameter Name="PSupplimentary1" Type="String" />
    </UpdateParameters>
    <DeleteParameters>
    <asp:parameter Name="PId" Type="Int64" />
    </DeleteParameters>
    </asp:ObjectDataSource>
    rgparkins, Oct 5, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hangar18
    Replies:
    0
    Views:
    10,332
    hangar18
    Mar 27, 2006
  2. =?Utf-8?B?UCBL?=

    DataGridView - Determine if a row has been edited

    =?Utf-8?B?UCBL?=, Apr 20, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    858
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    Apr 20, 2006
  3. Replies:
    4
    Views:
    906
  4. S_K
    Replies:
    5
    Views:
    18,313
  5. John C. Marx

    DataGridView - Edit Multiple Cells

    John C. Marx, Jul 5, 2007, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    975
    John C. Marx
    Jul 5, 2007
Loading...

Share This Page