Using Checkboxes Within the DataGrid Control to Select Records

Discussion in 'ASP .Net' started by sianan, Oct 26, 2005.

  1. sianan

    sianan Guest

    I have an ASP.NET custom control, which contains a DataGrid with
    checkboxes. I am trying to figure out how to retrieve the selected
    records, based on the checkbox's checked state. I want to send the
    results to a list control on the containing .ASPX page.

    Here is what I have in my code behind (C#):

    <%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
    AutoEventWireup="false" Inherits="WebApplication5.WebForm1" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>WebForm1</title>
    <meta content="Microsoft Visual Studio .NET 7.1"
    name="GENERATOR">
    <meta content="C#" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5"
    name="vs_targetSchema">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    <div style="OVERFLOW: auto; WIDTH: 100%; HEIGHT: 200px">
    <asp:DataGrid id="DataGrid1" runat="server" style="Z-INDEX: 102;
    LEFT: 24px; POSITION: absolute; TOP: 32px" Height="120px">
    <Columns>
    <asp:TemplateColumn>
    <ItemTemplate>
    <INPUT type="checkbox">
    </ItemTemplate>
    </asp:TemplateColumn>
    </Columns>
    </asp:DataGrid></div>
    </form>
    </body>
    </HTML>

    I looked for examples via Google, Yahoo, etc. but couldn't find much in
    the way of C#. Any help would be appreciated.
     
    sianan, Oct 26, 2005
    #1
    1. Advertising

  2. sianan,

    I have example code for doing exactly this on my website.
    http://www.aboutfortunate.com?page=codelibrary

    Use the textbox there to search for "checkbox in datagrid" and you'll have
    the example code.


    --
    Sincerely,

    S. Justin Gengo, MCP
    Web Developer / Programmer

    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzsche
    "sianan" <> wrote in message
    news:...
    >I have an ASP.NET custom control, which contains a DataGrid with
    > checkboxes. I am trying to figure out how to retrieve the selected
    > records, based on the checkbox's checked state. I want to send the
    > results to a list control on the containing .ASPX page.
    >
    > Here is what I have in my code behind (C#):
    >
    > <%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
    > AutoEventWireup="false" Inherits="WebApplication5.WebForm1" %>
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    > <HTML>
    > <HEAD>
    > <title>WebForm1</title>
    > <meta content="Microsoft Visual Studio .NET 7.1"
    > name="GENERATOR">
    > <meta content="C#" name="CODE_LANGUAGE">
    > <meta content="JavaScript" name="vs_defaultClientScript">
    > <meta content="http://schemas.microsoft.com/intellisense/ie5"
    > name="vs_targetSchema">
    > </HEAD>
    > <body MS_POSITIONING="GridLayout">
    > <form id="Form1" method="post" runat="server">
    > <div style="OVERFLOW: auto; WIDTH: 100%; HEIGHT: 200px">
    > <asp:DataGrid id="DataGrid1" runat="server" style="Z-INDEX: 102;
    > LEFT: 24px; POSITION: absolute; TOP: 32px" Height="120px">
    > <Columns>
    > <asp:TemplateColumn>
    > <ItemTemplate>
    > <INPUT type="checkbox">
    > </ItemTemplate>
    > </asp:TemplateColumn>
    > </Columns>
    > </asp:DataGrid></div>
    > </form>
    > </body>
    > </HTML>
    >
    > I looked for examples via Google, Yahoo, etc. but couldn't find much in
    > the way of C#. Any help would be appreciated.
    >
     
    S. Justin Gengo, Oct 26, 2005
    #2
    1. Advertising

  3. You'll have to loop through the grid rows, using a FindControl() to grab the
    checkbox, (you'll have to give the checkbox and id). At that point you can
    check the true/false of the checked property.

    --
    Curt Christianson
    site: http://www.darkfalz.com
    blog: http://blog.darkfalz.com



    "sianan" wrote:

    > I have an ASP.NET custom control, which contains a DataGrid with
    > checkboxes. I am trying to figure out how to retrieve the selected
    > records, based on the checkbox's checked state. I want to send the
    > results to a list control on the containing .ASPX page.
    >
    > Here is what I have in my code behind (C#):
    >
    > <%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
    > AutoEventWireup="false" Inherits="WebApplication5.WebForm1" %>
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    > <HTML>
    > <HEAD>
    > <title>WebForm1</title>
    > <meta content="Microsoft Visual Studio .NET 7.1"
    > name="GENERATOR">
    > <meta content="C#" name="CODE_LANGUAGE">
    > <meta content="JavaScript" name="vs_defaultClientScript">
    > <meta content="http://schemas.microsoft.com/intellisense/ie5"
    > name="vs_targetSchema">
    > </HEAD>
    > <body MS_POSITIONING="GridLayout">
    > <form id="Form1" method="post" runat="server">
    > <div style="OVERFLOW: auto; WIDTH: 100%; HEIGHT: 200px">
    > <asp:DataGrid id="DataGrid1" runat="server" style="Z-INDEX: 102;
    > LEFT: 24px; POSITION: absolute; TOP: 32px" Height="120px">
    > <Columns>
    > <asp:TemplateColumn>
    > <ItemTemplate>
    > <INPUT type="checkbox">
    > </ItemTemplate>
    > </asp:TemplateColumn>
    > </Columns>
    > </asp:DataGrid></div>
    > </form>
    > </body>
    > </HTML>
    >
    > I looked for examples via Google, Yahoo, etc. but couldn't find much in
    > the way of C#. Any help would be appreciated.
    >
    >
     
    =?Utf-8?B?Q3VydF9DIFtNVlBd?=, Oct 26, 2005
    #3
  4. sianan

    sianan Guest

    Thank you for the response!

    I did indeed find the code, the problem is that it is in VB.NET. For
    some reason, I wasn't able to convert it into C#. Still trying.....
     
    sianan, Oct 27, 2005
    #4
  5. sianan

    sianan Guest

    Thanks for the response. I appreciate your help.

    Still trying to get this to work with C#.
     
    sianan, Oct 27, 2005
    #5
  6. Sianan,

    I'd be happy to help you convert it. Send me what you have so far if you'd
    like (less typing for me that way) or tell me where you're hung up.

    --
    Sincerely,

    S. Justin Gengo, MCP
    Web Developer / Programmer

    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzsche
    "sianan" <> wrote in message
    news:...
    > Thank you for the response!
    >
    > I did indeed find the code, the problem is that it is in VB.NET. For
    > some reason, I wasn't able to convert it into C#. Still trying.....
    >
     
    S. Justin Gengo, Oct 27, 2005
    #6
    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. Ratman
    Replies:
    2
    Views:
    1,549
    Ratman
    Jul 4, 2004
  2. Angela
    Replies:
    0
    Views:
    352
    Angela
    Nov 16, 2004
  3. Patrick.O.Ige
    Replies:
    0
    Views:
    681
    Patrick.O.Ige
    Nov 3, 2005
  4. Matt
    Replies:
    2
    Views:
    214
    Roland Hall
    Jan 11, 2004
  5. Toboja
    Replies:
    3
    Views:
    108
    Toboja
    Jan 3, 2005
Loading...

Share This Page