Datagrid & checkbox column

Discussion in 'ASP .Net Datagrid Control' started by et, Nov 30, 2004.

  1. et

    et Guest

    All the articles on checkboxes in a datagrid revolve around using the
    checkboxes for user selection.

    I need to have a checkbox inserted and its value based on a the dataset the
    grid is bound to. How do I retrieve that value?

    This is my datagrid:
    <asp:datagrid id=dg runat="server" AutoGenerateColumns="False"
    CellPadding="3" BackColor="White" BorderColor="#999999" BorderWidth="1px"
    GridLines="Vertical" BorderStyle="None" >
    <Columns>
    <asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update"
    CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
    <asp:ButtonColumn Text="Delete" CommandName="Delete"></asp:ButtonColumn>
    <asp:BoundColumn Visible="False" DataField="ID"
    ReadOnly="True"></asp:BoundColumn>
    <asp:TemplateColumn HeaderText="FeePaid">
    <ItemTemplate>
    <%#Container.DataItem("FeePaid")%>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:CheckBox runat="server" ID="chkFeePaid"/>
    </EditItemTemplate>
    </asp:TemplateColumn>
    </asp:datagrid

    I don't know what to put in the code to get the checkbox, upon editing the
    row, to get the value of the cell, then check or uncheck the checkbox
    accordingly. I would also need to update the dataset and database with the
    new value.
    et, Nov 30, 2004
    #1
    1. Advertising

  2. et

    Guest

    et wrote:
    > I need to have a checkbox inserted and its value based on a the dataset the
    > grid is bound to. How do I retrieve that value?


    Hi et,
    I had some code to do just that - I'm sure you can figure it out, but if you
    need clarification let me know.

    private void dgdRegions_ItemCreated(
    object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if (e.Item.ItemType == ListItemType.Item ||
    e.Item.ItemType == ListItemType.AlternatingItem)
    {
    DataRowView drvTemp = (DataRowView)e.Item.DataItem;
    CheckBox chkCreate = (CheckBox)e.Item.FindControl("chkTemp");
    chkCreate.Checked = bool.Parse(drvTemp["contract"].ToString());
    }
    }

    I have a little datagrid demo with checkboxes, paging and dropdowns on my
    website. You can download it from http://mamakin1976.plus.com/download.

    HTH

    --
    Software is like sex: it's better when it's free -- [Linus Torvalds]

    Fabio Marini - A+, RHCT, MCDBA, MCAD.NET
    To reply: news [at] mamakin1976 [dot] plus [dot] com
    , Dec 5, 2004
    #2
    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. Ryan Lafferty

    DataGrid control with checkbox template column

    Ryan Lafferty, Aug 8, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    3,287
    Ryan Lafferty
    Aug 8, 2005
  2. Javier
    Replies:
    2
    Views:
    4,106
    Javier
    Dec 12, 2005
  3. =?Utf-8?B?RG90TmV0RGV2?=

    DataGrid and embeded Checkbox..How to find if checkbox clicked

    =?Utf-8?B?RG90TmV0RGV2?=, Oct 6, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    806
    David Wier
    Oct 6, 2006
  4. Gregory Rampton

    Convert an MS Access Yes/No column to a checkbox column in C# datagrid

    Gregory Rampton, Aug 6, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    198
    Gregory Rampton
    Aug 6, 2003
  5. Joey Pang
    Replies:
    4
    Views:
    508
    Joey Pang
    Jun 13, 2005
Loading...

Share This Page