Updating DataList Row by Row

Hello,

I have a datalist on my web page which displays a list of records from my database, all the information is displayed in labels except for one which is in a DropDownBox and the user can select Yes or No.  I want to update each record individual based on the value in the dropdownbox.  My problem is currently if I change the last record to say No then all the records in the db change to No.  It is not recording the new values row by row.

Anybody got ideas why?

Thanks


Regards,
Steven
0
sbucello
4/19/2008 7:17:38 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

7 Replies
906 Views

Similar Articles

[PageSpeed] 0

I don't think is the DataList because I used in that way myself many times

Post some code so we can help you


I am not anti social, am just not user friendly
0
aamador
4/19/2008 10:15:35 PM

Please see my code below.  Thanks 

 <asp:DataList ID="DataList_UpdateRegisteration" runat="server" DataSourceID="SqlDataSource_SessionAttendee" CellPadding="4" ForeColor="#333333" DataKeyField="RecordID">
                    <FooterTemplate>
                    
                    <asp:Button ID="btnSubmit" OnClick="btnSubmit_Click"
                    Text="Update Registration Records" runat="server">
                    </asp:Button>

                    </FooterTemplate>
                    <HeaderTemplate>
                        <table>
                            <tr>
                                <td style="width: 100px; text-align: center;">
                                    <span style="color: #ffffff">Store Number</span></td>
                                <td style="width: 100px; text-align: center;">
                                    <span style="color: #ffffff">Store Name</span></td>
                                <td style="width: 100px; text-align: center;">
                                    <span style="color: #ffffff">Title</td>
                                <td style="width: 100px; text-align: center;">
                                    <span style="color: #ffffff">First Name</td>
                                <td style="width: 100px; text-align: center;">
                                    <span style="color: #ffffff">Last Name</td>
                                <td style="width: 100px; text-align: center;">
                                    <span style="color: #ffffff">Position</td>
                                <td style="width: 100px; text-align: center;">
                                    <span style="color: #ffffff">Execution Checklist Complete</td>
                                <td style="width: 100px; text-align: center;">
                                    <span style="color: #ffffff">Status</td>
                            </tr>
                        </table>

                    </HeaderTemplate>
                    <ItemTemplate><table>
                        <tr>
                            <td style="width: 100px; text-align: left;">
                                <%# DataBinder.Eval(Container.DataItem,"StoreNumber").ToString() %>
                            </td>
                            <td style="width: 100px; text-align: left;">
                                <%#DataBinder.Eval(Container.DataItem, "StoreName").ToString()%>
                            </td>
                            <td style="width: 100px; text-align: left;">
                                <%# DataBinder.Eval(Container.DataItem,"Title").ToString() %>
                            </td>
                            <td style="width: 100px; text-align: left;">
                                <%# DataBinder.Eval(Container.DataItem,"FirstName").ToString() %>
                            </td>
                            <td style="width: 100px; text-align: left;">
                                <%# DataBinder.Eval(Container.DataItem,"LastName").ToString() %>
                            </td>
                            <td style="width: 100px; text-align: left;">
                                <%# DataBinder.Eval(Container.DataItem,"Position").ToString() %>
                            </td>
                            <td style="width: 100px; text-align: left;">
                                <asp:DropDownList ID="DropDownList_ExecutionChecklist" DataValueField="DropDownList_ExecutionChecklist" 
                                          DataTextField="ExecutionChecklist"
                                          runat="server">
                                              <asp:ListItem>No</asp:ListItem>
                                              <asp:ListItem Selected="True">Yes</asp:ListItem>
                                          </asp:DropDownList></td>
                            <td style="width: 100px; text-align: left;">
                                <%#DataBinder.Eval(Container.DataItem, "Status").ToString()%>
                            </td>
                        </tr>
                    </table>
                    </ItemTemplate>
                    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <AlternatingItemStyle BackColor="White" ForeColor="#284775" />
                    <ItemStyle BackColor="#F7F6F3" ForeColor="#333333" />
                    <SelectedItemStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                </asp:DataList>
                <asp:SqlDataSource ID="SqlDataSource_SessionAttendee" runat="server"
                    ConnectionString="<%$ ConnectionStrings:CONNECTIONSTRING%>"
                    ProviderName="<%$ ConnectionStrings:CONNECTIONSTRING.ProviderName %>"
                    SelectCommand="SELECT [StoreNumber], [StoreName], [RecordID], [Title], [FirstName], [LastName], [Position], [AttendedClass], [ExecutionChecklist], [Status] FROM [tblRegisterations] WHERE (([TrainingSession] = @TrainingSession) AND ([TrainingStore] = @TrainingStore)) ORDER BY LastName DESC"
                    UpdateCommand="UPDATE [tblRegisterations] SET [ExecutionChecklist] = @ExecutionChecklist, [Status] = 'Completed'">
                    
                    <SelectParameters>
                        <asp:ControlParameter ControlID="lblTrainingSession" Name="TrainingSession" PropertyName="Text" Type="String" />
                        <asp:ControlParameter ControlID="lblStoreName" Name="TrainingStore" PropertyName="Text" Type="String" />
                             
                    </SelectParameters>

                    <UpdateParameters>
                        <asp:Parameter Name="StoreNumber" Type="String" DefaultValue="" />
                        <asp:Parameter Name="StoreName" Type="String" />
                        <asp:Parameter Name="Title" Type="String" />
                        <asp:Parameter Name="FirstName" Type="String" />
                        <asp:Parameter Name="LastName" Type="String" />
                        <asp:Parameter Name="Position" Type="String" />
                        
                        <asp:ControlParameter PropertyName="Text" Type="String" Name="ExecutionChecklist" ControlID="ctl00$MainContent$DataList_UpdateRegisteration$ctl01$DropDownList_ExecutionChecklist" />
                        <asp:Parameter Name="Status" Type="String" DefaultValue="Completed" />
                    </UpdateParameters>
                
                </asp:SqlDataSource>
               
 
Regards,
Steven
0
sbucello
4/19/2008 11:55:18 PM

Hi sbucello ,

I guess the problem is here:

sbucello:

UpdateCommand="UPDATE [tblRegisterations] SET [ExecutionChecklist] = @ExecutionChecklist, [Status] = 'Completed'">

The update command update all the rows in table. It should be : update table set field = value where id = 1 , so it can update value row by row.

My suggestion is to write some code at codebehind. Loop through all items in datalist, invoke findcontrol() method to retrieve dropdownlist control so you can get it's selected value. And you can get the row's datakey through DataList's datakey property. After you get the id and it's status , you can use Ado.Net to update the record.

 

 



Samu Zhang
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
0
Samu
4/22/2008 2:51:25 AM

Hello,

Thank you for your reply.  I understand the concept behind the solution but do not know the coding to use.  Can you please help me with the FindControl() coding to populate the ID number for each record retrived to change the Status for that record only to Completed.

 Thanks


Regards,
Steven
0
sbucello
4/22/2008 8:26:05 AM

Does anybody know how to get this working.

 

My update command is ="UPDATE [tblRegisterations] SET [ExecutionChecklist] = @ExecutionChecklist, [Status] = 'Completed' WHERE RecordID=@RecordID"

But still dont know how to use the FindControl to loop through the datalist to update the required row.

Any help would be great.

 


Regards,
Steven
0
sbucello
4/25/2008 5:08:36 AM

Steven,

 What your are attempting to do as shown in your code is wrong!! You have a number of issues starting with your UpdateCommand on down to how your are trying to bind to the dropdown.

If you like I can give you a way of doing this but it will require code. If you want the declarative model to work then you must follow the rule otherwise you have to code.  If you like to see a working example using what you gave me let me know.


I am not anti social, am just not user friendly
0
aamador
4/25/2008 12:01:28 PM

Thank you for your reply, refering to a post on my other thread that I started because I changed from a DataList to a Repeater.  I have made some changes to by coding as shown below;  But if you are able to provide working examples I would be greatly appricated.  Thanks in advancded.

My code is on this thread;

 

http://forums.asp.net/p/1252878/2321094.aspx#2321094

 

Thanks heaps


Regards,
Steven
0
sbucello
4/25/2008 12:41:26 PM
Reply:

Similar Artilces:

Row updating, row updated confusion
Okay this is the first time I've ever had to do code behind for row updating logic in a gridview. So be patient with me if it's totally incorrect. Do I put the gridview rebind code in the Row Updating or Updated event?  Currently, I have it in both as I'm simply troubleshooting to try to get it to work.  With this code, not only is the record not updating but the record disappears from the gridview upon refreshing.Protected Sub GridView2_RowUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdatedEventArgs) Handles GridView2.RowUpdated ...

Add new controls to a gridview row; when editing that row using the edit row feature in the gridview control.
Hi all  I have a questions that looks hard / complex to me, and i know you can help me in this. Q {  I have row in a Gridview and i have an edit option to it. I press the edit button, to edit the values in that row and update data all the way back to the database. Now when i press the edit button, i want a drop down list to be displayed that contain values for a particular field in my grid view. (for now only plain text boxes appear.) } I hope you understand my question, all i need to do is replace the text box controls with a dropdown list when i am editing a row in ...

question about updating a row? How to update a different row.
I will try to make this as simple as I can. k, here I go. I originally populate my datagrid with data. Then during the edit mode, I can populate information by an ontextchanged event, which is actually bringing in a new row (essentially). My problem occurs when I try to update the data. Since the row was originally populated with the data, it updates that row in the table. But since I did an ontextchanged, I want to update that row instead. Not the original row. If I do an update, then I have two identical rows of data in my table, but with different primary keys. How can I update t...

warning: update row ... is a conflict update and this row is ignored
SQL Anywhere 10.0.1.3488 I am synching one SQL Anywhere database to another through MobiLink, getting this warning: W. 2008-08-19 13:01:01. <17> [10037] Ignoring updated row (new values) W. 2008-08-19 13:01:01. <17> [10038] Ignoring updated row (old values) W. 2008-08-19 13:01:01. <17> [10072] The update row for table '<orders>' is a conflict update and this row is ignored. There are currently no conflict resolution scripts in place, so I would expect the default behavior of "last one in wins" rather than seeing "this row is ign...

update multi row when i meant update single row
RGVhciBhbGw6DQoNCkkgdHJpZWQgdG8gdXBkYXRlIGEgc2luZ2xlIHJvdyBmb3IgdGhlIGRh dGFiYXNlLCBob3dldmVyLCB0aGUgcXVlcnkgaGVyZQ0KdXBkYXRlIG11bHRpcGxlIHJvd3MN Cg0KbXkgJHNxbCA9ICJVUERBVEUgdXB0aW1lIFNFVCB1cF90aW1lPSRuZXdfdXB0aW1lDQog ICAgICAgICAgICAgV0hFUkUgaG9zdG5hbWUgPSAnJGhvc3QnIGFuZA0KICAgICAgICAgICAg IHN0YXJ0ZGF0ZT0gKHNlbGVjdCBNQVgoc3RhcnRkYXRlKSBmcm9tIHVwdGltZSB3aGVyZQ0K ICAgICAgICAgICAgIGhvc3RuYW1lID0nJGhvc3QnIGFuZCB1cF90aW1lID0gJG9sZHVwdGlt ZSkgIjsNCg0KSSBtZWFudCBvbmx5IHdhbnQgdG8gdXBkYXRlIGxhdGVzdCBzdGFydGRhdGUs IHNvbWVob3csIGl0IHJldHVybnMgYWxsDQp0aGUgc3RhcnRkYXRlIHdoaWNoIHVwX3RpbWUg PSRvbGR1...

(Fwd) How to loop through a database, row by row, and select and update one row at a time
----- Forwarded message from Troy Mulder <mulderta@gmail.com> ----- Date: Mon, 12 Apr 2010 17:48:37 -0400 From: Troy Mulder <mulderta@gmail.com> To: Tim.Bunce@pobox.com Subject: How to loop through a database, row by row, and select and update one row at a time Hello Tim (is it Dr. Bunce?), My name is Troy Mulder, and I am trying to get a perl script to interface with a PostgreSQL database. I am trying to step through each row of the database, and read one column of the row, and update another column of the row. When I follow the online tutorial a...

First Row, Next Row, Prior Row, Last Row
I have a SQL Anywhere 7.0 Database, have a table Product_detail which contains Column Name Datatype width Null Default batch_id char(10) No None prod_id Integer No None employee_id Integer No None quantity Integer No None price Numeric (14, 2) No None Its primary key is batch_id I have a Freeform Datawindow with this table I want to provide the first row, next row, prior row and last row Ho...

?? On remote
9.0.2.3274 On the remote I insert a row. I then subsequently update that row. All before synchronizing. I don't know what changed, but I don't get my modifications in the consolidated. When I synchronize the remote with the consolidated, the upload_insert event gets fired with the initial insert (non-PK columns with no data) but I do not get the upload_update event to fire with the data I used when I updated the new row on the remote. ??? In this scenario with an insert and then an update, should the upload_insert have the modified data or should there be an up...

Update all Row rows in a list view
Hi, i know it not the best pratice but i need to do it. I need to create a button that will update all the rows in a listview. I have found tutorial how to do it in a gridview. http://fredrik.nsquared2.com/viewpost.aspx?PostID=202  Anyone have any idea. What i did so far. 1: But a textbox in each row2: Create a button in the footer of the listeview with CommandName = "EditNote"3: Find how many row there is with ListView1.Items.Count4:Now my problem is there a way to do somthing like thisFor i = 1 to intCountRow      Dim txtElement1 As TextBox= e.It...

Datalist Mutliple row in one row
Hi,I have a sql view with the following output:Time                    Header    Text       RowC10:15:34 AM        News1     ABC       110:15:34 AM        News1     DEFG     210:15:34 AM        News1     HIJKL      311:19:39 AM      ...

Scroll row by row in a datawindow control
Hi. I have a tabular datawindow object with one group and all my data is displayed in the header group and the detail band is not visible. when i run my application and i want to scroll the data the datawindow control scrolls the data page by page and i need it row by row. How can i do this? thank you in advanced You will have to move your data into the detail band. "Row" in datawindow is contents of the detail band. Igor "Fernando Pe�a" <Fernando_Pe0xL1A4za> wrote in message news:943886BF87C590640077873785256A65.0077874785256A65@webforums.....

Updating and binding control to other controls within the same row of a GridView
HiIn the EditTemplate of my GridView I show 2 DropDownLists. When the user selects the first dropdownlist, I need it to update the contents of the second dropdownlist. I have my Subs that do this fine when not inside the GridView, but what is the correct way to do it whilst they are in the GridView?This is my current attempt that returns the error 'Object reference not set to an instance of an object'. I presume its related to correctly targeting the DropDownList in question? This is my GridView:<asp:GridView ID="GridView1" runat="server"  &...

how to update a row using a seperate update button not command button without selecting the row?
How to update a row using a seperate update button not command button without selecting a row? Simple question but dificult to do. The reason I ask this is that when a user clicks 'Update' I want each row to update the database. Please note I can't use findcontrol as their are no headers This is my code so far: protected void UpdateButton_Click(object sender, EventArgs e){    foreach (GridViewRow row in CellGridView.Rows)     {          string stext = CellGridView.Rows.ToString();     &nb...

DataSet rows being deleted, but after the update , the sql database is not updated. The delete rows still in the database.
 Stepping thru the code with the debugger shows the dataset rows being deleted.   After executing the code, and getting to the page presentation. Then I stop the debug and start the page creation process again ( Page_Load ).    The database still has the original deleted dataset rows. Adding rows works, then updating works fine, but deleting rows, does not seem to work.   The dataset is configured to send the DataSet updates to the database. Use the standard wizard to create the dataSet.     cDependChildTA.Fill(cDependChildDs._ClientDependentC...

Web resources about - Updating DataList Row by Row - asp.net.presentation-controls

Wikipedia talk:Updating information - Wikipedia, the free encyclopedia
This is brilliant! It would probably work best for elections etc in minor locations. For something that's well-known like a US predidential election, ...

8 Tools For Updating Facebook Offsite
Applications for receiving Facebook updates and notifications without having to keep the site open in a browser keep coming out. Here are eight ...

Updating how Cost per Click is Measured on Facebook
To help advertisers better understand how their ads perform, we're updating the definition of cost per click on Facebook. Learn what the change ...

Updating Your App for iOS 9: What You Need to Know
Updating Your App for iOS 9: What You Need to Know

Facebook for iPhone 3.0 to Include Page Updating
... who want to more easily update their Facebook Pages on the go: Facebook for iPhone 3.0 , which should be released soon, will include Page updating, ...

Updating trends on mobile
Trends are a great way to find out what people are talking about on Twitter at a given moment and at a single glance. Starting today, we’re making ...

Delhi Metro Fare Calculator and Auto-Updating Map on the App Store on iTunes
Get Delhi Metro Fare Calculator and Auto-Updating Map on the App Store. See screenshots and ratings, and read customer reviews.


Updating Emma: Jane Austen's classic joins list of literary reworks
Jane Austen published six novels. Just six. She died before she completed the seventh.

Tips For Updating Your Appearance
Like Joe Hockey, all men can pull off a radical mid-life makover by following some simple guidelines.

Resources last updated: 12/20/2015 4:47:57 PM