[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Datagrid with Multiple Select Checkboxes

Posted on 2004-09-02
1
Medium Priority
?
274 Views
Last Modified: 2011-09-20
Hi,

I have a datagrid with a list of items, and I want to be able to have a column that contains checkboxes and then a button below that postbacks. On postback, I want to be able to determine which rows were checked. How can I do this without a postback for each checkbox being checked?

Thanks!
0
Comment
Question by:tonypino123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 17

Accepted Solution

by:
AerosSaga earned 1500 total points
ID: 11964326
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="RadioButtonInDataGrid.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
      <HEAD>
            <title>WebForm1</title>
            <meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
            <meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
            <meta name="vs_defaultClientScript" content="JavaScript">
            <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
      </HEAD>
      <body MS_POSITIONING="GridLayout">
            <form id="Form1" method="post" runat="server">
                  <asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 8px" runat="server" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="4" AutoGenerateColumns="False" Width="144px" Height="22px">
                        <SelectedItemStyle Font-Bold="True" ForeColor="#663399" BackColor="#FFCC66"></SelectedItemStyle>
                        <ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
                        <HeaderStyle Font-Bold="True" ForeColor="#FFFFCC" BackColor="#990000"></HeaderStyle>
                        <FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
                        <Columns>
                              <asp:TemplateColumn HeaderText="Select">
                                    <ItemTemplate>
                                          <asp:Label id="Label2" runat="server"></asp:Label>
                                    </ItemTemplate>
                              </asp:TemplateColumn>
                              <asp:BoundColumn DataField="lastname" HeaderText="Last Name"></asp:BoundColumn>
                        </Columns>
                        <PagerStyle HorizontalAlign="Center" ForeColor="#330099" BackColor="#FFFFCC"></PagerStyle>
                  </asp:DataGrid>
                  <asp:Label id="Label3" style="Z-INDEX: 103; LEFT: 222px; POSITION: absolute; TOP: 35px" runat="server" Width="184px"></asp:Label>
                  <asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 218px; POSITION: absolute; TOP: 70px" runat="server" Text="Display Selected Value"></asp:Button>
            </form>
      </body>
</HTML>

----------------------------------------------------------------------------------------------------------------------

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not Page.IsPostBack Then
            BindGrid()
        End If
    End Sub

    Sub BindGrid()
        Dim connstr As String = "Integrated Security=SSPI;Initial Catalog=Northwind;Data Source=.\NetSDK"
        Dim cnn As SqlConnection
        Dim da As SqlDataAdapter
        Dim ds As New DataSet()
        cnn = New SqlConnection(connstr)
        da = New SqlDataAdapter("select * from employees", cnn)
        da.Fill(ds, "employees")
        DataGrid1.DataSource = ds
        DataGrid1.DataBind()
    End Sub

    Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
        If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then
            Dim r As Label
            r = e.Item.FindControl("Label2")
            r.Text = "<input type=radio name='myradiogroup' value=" & e.Item.Cells(1).Text & ">"
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Label3.Text = Request.Form("myradiogroup")
        Dim i As DataGridItem
        For Each i In DataGrid1.Items
            If i.ItemType = ListItemType.AlternatingItem Or i.ItemType = ListItemType.Item Then
                Dim r As Label
                r = i.FindControl("Label2")
                If r.Text.IndexOf(Label3.Text) > 0 Then
                    r.Text = "<input type=radio name='myradiogroup' value=" & i.Cells(1).Text & " checked>"
                Else
                    r.Text = "<input type=radio name='myradiogroup' value=" & i.Cells(1).Text & ">"
                End If
            End If
        Next
    End Sub
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question