• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 475
  • Last Modified:

asp:DataList CheckBox Multi-Update

I have a Datalist with some data and a simple checkbox. I want it to be used to update a BIT value in my database for that row of data.  Using a button on the page.

I can't seem to get passed the EVENT FIRING haha

I am not sure what I am doing wrong, But what I do want to do Is update the database for each box that is checked with the value true!

Help!


<div id="Inbox" class="container">
 <table width="500" border="1">
 <tr>
<td valign="top" width="300" height="50" colspan="2">
 
 
    <asp:Button ID="DeleteButton" runat="server" Text="Delete Selected" />
 
 
<asp:DataList id="InboxRepeater" runat="server" EnableViewState="False" Width="400px" OnDeleteCommand="UserDeleteThread">     
    <HeaderTemplate>
    <tr>
        <td colspan="2"><asp:Label ID="RealNameLabel" runat="server" Text="Name: " Font-Bold="true"/></td>
        <td> <asp:Label ID="SentLabel" runat="server" Text="Sent: " Font-Bold="true"/></td>                   
        <td><asp:Label ID="Label2" runat="server" Text="Subject: " Font-Bold="true"/></td>
    </tr>
    </HeaderTemplate>
 
    <ItemTemplate>
                    <tr>
                        <td>
                        <a href="/Messages/ReadThread.aspx?ThreadID=<%# DataBinder.Eval(Container.DataItem, "ThreadId") %>&FriendID=<%# DataBinder.Eval(Container.DataItem, "SenderId") %>">
                        <img src="/Profile/DisplayUserThumb.aspx?UserId=<%# DataBinder.Eval(Container.DataItem, "SenderId") %>" 
                            alt="<%# DataBinder.Eval(Container.DataItem, "RealName") %>" width="50" /></a>                    
                        </td>
                        <td> 
                        <asp:CheckBox runat="server" Checked="false"/>
                        </td>
                        <td>
                        
                        <%#DataBinder.Eval(Container.DataItem, "RealName")%>
                        </td>
                        <td>
                        <%#DataBinder.Eval(Container.DataItem, "TimeSent")%>                      
                        </td>
                        <td>
                        <%#DataBinder.Eval(Container.DataItem, "Subject")%>
                        </td>
                        
                    </tr>
 
 
                
                
    </ItemTemplate>
 
</asp:DataList>
 
</td>
</tr>
</table>
 
    
</div>
 
 
------ fill datalist
 
Dim adapter As New SqlDataAdapter
 
                Try
                    Dim InboxSelectResultSet As New DataSet
 
                    'Connection
                    Using myConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("AGConnectionString").ConnectionString)
 
                        Using myCommand As New SqlCommand("AGInboxSelect", myConnection)
 
 
                            myCommand.CommandType = CommandType.StoredProcedure
                            myCommand.Parameters.AddWithValue("@UserID", CurrentUser)
 
                            myConnection.Open()
 
                            Using da As New SqlDataAdapter("AGInboxSelect", myConnection)
                                da.SelectCommand = myCommand
                                da.Fill(InboxSelectResultSet)
                            End Using
 
                            myConnection.Close()
                        End Using
 
 
                        'ASP Repeater with an Id of "InboxRepeater"
                        Me.InboxRepeater.DataSource = InboxSelectResultSet.Tables(0)
                        Me.InboxRepeater.DataBind()
 
                    End Using
                Catch ex As Exception
                    'do something
                End Try
 
--- delete sub
 
    Sub UserDeleteThread(ByVal sender As Object, _
                   ByVal e As DataListCommandEventArgs)
 
        Server.Transfer("UpdateConfirm.aspx")
    End Sub

Open in new window

0
HarleySkater
Asked:
HarleySkater
  • 7
  • 3
1 Solution
 
prairiedogCommented:
>>>I can't seem to get passed the EVENT FIRING haha
Do you mean the UserDeleteThread is not firing when you click the delete button?
0
 
HarleySkaterAuthor Commented:
it does a postback, but in the behind code it never touches the UserDeleteThread sub
0
 
HarleySkaterAuthor Commented:
basicly I don't care how it happens hahah, but I want to have a set of records, that displays on the page, from a really tricky stored procedure.
Then I want to be able to allow the people to looking at that page to check the boxes in the page and then update that checkbox value for those rows to the server.

I keep running into problems because I have to pass the UserId for that use into the the stored procedure.

I have started from scratch on this like 5 times.
0
Industry Leaders: 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!

 
HarleySkaterAuthor Commented:
I really don't care if its gridview, datalist or whatever as long as it can just allow me to use this stored procedure and allow me to update !!!!
0
 
prairiedogCommented:
Your event handler has wrong signature. Did you create the event handler manually yourself?
0
 
HarleySkaterAuthor Commented:
I double clicked the button I had in my datalist, not the button that was above the datalist that I added later.  I seriously did start over on this like 5 times.  Hahaha I think I am just going to restart this topic here.
------ page code
 
<div id="Inbox" class="container">
 <table width="500" border="1">
 <tr>
<td valign="top" width="300" height="50" colspan="2">
 
 
    <asp:GridView ID="InboxGridView" runat="server" AllowPaging="True" 
        AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ThreadId" 
        EmptyDataText="There are no data records to display.">
        <Columns>
            <asp:BoundField DataField="ThreadId" HeaderText="ThreadId" ReadOnly="True" 
                SortExpression="ThreadId" />
            <asp:BoundField DataField="SenderId" HeaderText="SenderId" 
                SortExpression="SenderId" />
            <asp:BoundField DataField="RecipientId" HeaderText="RecipientId" 
                SortExpression="RecipientId" />
            <asp:CheckBoxField DataField="SenderDelete" HeaderText="SenderDelete" 
                SortExpression="SenderDelete" />
            <asp:CheckBoxField DataField="RecipientDelete" HeaderText="RecipientDelete" 
                SortExpression="RecipientDelete" />                
            <asp:BoundField DataField="Subject" HeaderText="Subject" 
                SortExpression="Subject" />
            <asp:BoundField DataField="RealName" HeaderText="Name" 
                SortExpression="RealName" />
        </Columns>
    </asp:GridView>
 
</td>
</tr>
</table>
 
    
</div>
 
------ behind code
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
        If Not IsPostBack Then
 
            If User.Identity.IsAuthenticated Then
 
                CurrentUser = Membership.GetUser().ProviderUserKey.ToString()
 
                Dim adapter As New SqlDataAdapter
 
                Try
                    Dim InboxSelectResultSet As New DataSet
 
                    'You should really considering moving data access and most logic into their own layers.
                    Using myConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("AGConnectionString").ConnectionString)
 
                        Using myCommand As New SqlCommand("AGInboxSelect", myConnection)
 
 
                            myCommand.CommandType = CommandType.StoredProcedure
                            myCommand.Parameters.AddWithValue("@UserID", CurrentUser)
 
                            myConnection.Open()
 
                            Using da As New SqlDataAdapter("AGInboxSelect", myConnection)
                                da.SelectCommand = myCommand
                                da.Fill(InboxSelectResultSet)
                            End Using
 
                            myConnection.Close()
                        End Using
 
 
                        'ASP Repeater with an Id of "InboxRepeater"
                        Me.InboxGridView.DataSource = InboxSelectResultSet.Tables(0)
                        Me.InboxGridView.DataBind()
 
                    End Using
                Catch ex As Exception
                    'do something
                End Try
 
 
            Else
                Server.Transfer("~/default.aspx")
                Exit Sub
            End If
        End If
 
    End Sub

Open in new window

0
 
HarleySkaterAuthor Commented:
gerrrrrrrrr I mean the page code should be this.
-------- Page code
 
<div id="Inbox" class="container">
 <table width="500" border="1">
 <tr>
<td valign="top" width="300" height="50" colspan="2">
 
 
    <asp:GridView ID="InboxGridView" runat="server" AllowPaging="True" 
        AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ThreadId" 
        EmptyDataText="There are no data records to display.">
        <Columns> 
            <asp:CheckBoxField HeaderText="Delete" />                    
            <asp:BoundField DataField="ThreadId" HeaderText="ThreadId" ReadOnly="True" 
                SortExpression="ThreadId" />
            <asp:BoundField DataField="SenderId" HeaderText="SenderId" 
                SortExpression="SenderId" />
            <asp:BoundField DataField="RecipientId" HeaderText="RecipientId" 
                SortExpression="RecipientId" />           
            <asp:BoundField DataField="Subject" HeaderText="Subject" 
                SortExpression="Subject" />
            <asp:BoundField DataField="RealName" HeaderText="Name" 
                SortExpression="RealName" />
        </Columns>
    </asp:GridView>
 
</td>
</tr>
</table>
 
    
</div>

Open in new window

0
 
prairiedogCommented:
So it seems you decided to use GridView and it is ok. I think I can help you with this, but don't change your mind in 5 minutes.
With mutiple update in your case, you need a button outside the GridView. Then in the Button's click event handler, you need to loop through the GridView and find the row that checked, then do the update.
0
 
HarleySkaterAuthor Commented:
I know right!, Im spazzing OUT hahaha

OK i am trying that NOW :D
0
 
HarleySkaterAuthor Commented:
got it !
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 7
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now