Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 1st, 2004, 01:25 AM
Authorized User
 
Join Date: Jul 2004
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using check boxes in datagrid

Hi,
   i am facing a problem with the checkboxes displayed in the datagrid.when the data are displayed, one of the columns has the checkboxes.Now i want that when i select some checkboxes, the rows corresponding to those selected, should be updated or deleted. I tried this using datagriditem and using a loop to search the entire data. But how can i get the value of the checkboxes to see whether it is clicked or not ? Please give some idea.

 
Old September 8th, 2004, 01:33 AM
Authorized User
 
Join Date: Jul 2004
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi again, this time i am sending my codings with this. Look at it and say what is the problem with this.I hope this time i will get a reply.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim con As SqlConnection
        Dim cmd1, cmd2 As SqlCommand
        Dim qry1, qry2 As String

        con = New SqlConnection("server= cabin61;uid=sa;pwd=;database=ab")
        con.Open()
        qry1 = "select rollno,name from chkbtry "
         cmd1 = New SqlCommand(qry1, con)
         DataGrid1.DataSource = cmd1.ExecuteReader()
        DataGrid1.DataBind()
        con.Close()
    End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim myDataGridItem As DataGridItem

        Dim chkSelected As System.Web.UI.WebControls.CheckBox

        Dim strStoreName As String

        Dim strStoreID As String
        Dim conn As SqlConnection
        Dim cmd3, cmd4 As SqlCommand
        Dim qry, qry2 As String
        Dim sqldrd As SqlDataReader
        For Each myDataGridItem In DataGrid1.Items
            chkSelected = myDataGridItem.FindControl("chkSelection")

           If chkSelected.Checked = True Then
        conn = New SqlConnection("server= cabin61;uid=sa;pwd=;database=ab")
        conn.Open()
        qry = "update chkbtry set name = '" & TextBox1.Text & "' where rollno=4"
        cmd3 = New SqlCommand(qry, conn)
        cmd3.ExecuteNonQuery()
        DataGrid1.DataBind()
        conn.Close()
        Response.Redirect("WebForm10.aspx")
        conn.Close()
         End If
         Next
    End Sub
End Class


<asp:datagrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 286px; POSITION: absolute; TOP: 157px" runat="server" AutoGenerateColumns="False" SelectedIndex="0">
                <Columns>
                    <asp:TemplateColumn HeaderText="RollNo">
                        <HeaderStyle Font-Names="Bookman Old Style" ForeColor="Black" BackColor="White"></HeaderStyle>
                        <ItemTemplate>
                            <asp:CheckBox ID="ChkSelection" Runat="server"></asp:CheckBox>
                            <asp:Label ID="hypDetails" Text='<%#DataBinder.Eval(Container.DataItem, "rollno")%>' runat="server">
                            </asp:Label>
                        </ItemTemplate>
                    </asp:TemplateColumn>
                    <asp:TemplateColumn HeaderText="Name">
                        <HeaderStyle Font-Names="Bookman Old Style" ForeColor="Black" BackColor="White"></HeaderStyle>
                        <ItemTemplate>
                            <asp:Label ID ="lbl1" Text='<%#DataBinder.Eval(Container.DataItem, "name")%>' runat="server">
                            </asp:Label>
                        </ItemTemplate>
                    </asp:TemplateColumn>
                </Columns>
            </asp:datagrid><asp:button id="Button1" style="Z-INDEX: 102; LEFT: 330px; POSITION: absolute; TOP: 336px" runat="server" Text="Enter"></asp:button><asp:label id="lblstatus1" style="Z-INDEX: 103; LEFT: 221px; POSITION: absolute; TOP: 393px" runat="server" Height="56px" Width="440px"></asp:label>
            <asp:TextBox id="TextBox1" style="Z-INDEX: 104; LEFT: 289px; POSITION: absolute; TOP: 81px" runat="server"></asp:TextBox></form>


I dont know where the problem is. Even no error message is comign but the data are not updated also.Please help.



 
Old September 8th, 2004, 08:28 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hello ractim,
Have a look at this thread
http://p2p.wrox.com/topic.asp?TOPIC_ID=17583
Hope this helps.

--------------------------------------------
Mehdi.:)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop over check boxes sams ASP.NET 1.0 and 1.1 Professional 5 July 17th, 2007 06:26 AM
Check Boxes Allan320 Access VBA 3 June 2nd, 2006 05:45 AM
Using check boxes to filter dstein4d Access VBA 13 January 25th, 2006 07:50 PM
Disable Check Boxes sweet4511 VB How-To 22 July 19th, 2005 03:53 PM
Getting value of Dynamic Check boxes kathryne Classic ASP Databases 3 March 19th, 2004 05:44 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.