Edit a Database Field when Checkboxed Value on Submit Click

 Hi,  I am new to VWD and VB, and I have been racking my brain for weeks on how to do this.  My main problem is I don't even know what I am looking for.  Am I looking for a VB script?  ASP script VB code?  No clue!

 Anyway, here is my question.  The ASP page below displays a GridView with a custom column I made for a checkbox.  When the submit button is clicked it runs the script at the top of the code and iterates through each row (or so I think) and checks for a checked box then, on line 20 I would like to update the Runner field of the selected row with the string variable userName.  I think everything works except I dont know how to update my database.  Also for future reference, is this part of the code that I am working on VB Script?  or what?  I think I have to create a connection to a database first then I am allowed to edit it.

 Thanks!

- John

1    <script runat="server">
2    
3        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
4        End Sub
5    
6        Protected Sub claimSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
7            Dim cnn As Data.SqlClient.SqlConnection = New Data.SqlClient.SqlConnection("server=(local);" & "database=Advertisers;Integrated Security=SSPI")
8    
9            Dim name As MembershipUser
10           Dim userName As String
11           
12           name = Membership.GetUser()
13           userName = name.UserName
14           
15           For index As Integer = 0 To GridView1.Rows.Count - 1
16               'Programmatically access the CheckBox from the TemplateField
17               Dim cb As CheckBox = CType(GridView1.Rows(index).FindControl("CheckBox1"), CheckBox)
18    
19               If cb.Checked Then
20                   
21   
22                   
23               End If
24           Next
25       End Sub
26   </script>
27   
28   <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
29       <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
30           SelectCommand="SELECT [Class], [Section], [Day], [Time], [Professor], [Enrolled], [Room], [RoomNumber], [Runner] FROM [Schedule]">
31       </asp:SqlDataSource>
32       <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
33           DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None">
34           <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
35           <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
36           <EditRowStyle BackColor="#999999" />
37           <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
38           <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
39           <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
40           <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
41           <Columns>
42               <asp:BoundField DataField="Class" HeaderText="Class" SortExpression="Class" />
43               <asp:BoundField DataField="Section" HeaderText="Section" SortExpression="Section" />
44               <asp:BoundField DataField="Day" HeaderText="Day" SortExpression="Day" />
45               <asp:BoundField DataField="Time" HeaderText="Time" SortExpression="Time" />
46               <asp:BoundField DataField="Professor" HeaderText="Professor" SortExpression="Professor" />
47               <asp:BoundField DataField="Enrolled" HeaderText="Enrolled" SortExpression="Enrolled" />
48               <asp:BoundField DataField="Room" HeaderText="Room" SortExpression="Room" />
49               <asp:BoundField DataField="RoomNumber" HeaderText="Number" SortExpression="RoomNumber" />
50               <asp:BoundField DataField="Runner" HeaderText="Runner" SortExpression="Runner" />
51               <asp:TemplateField HeaderText="Claim">
52                   <EditItemTemplate>
53                       <asp:CheckBox ID="CheckBox1" runat="server" />
54                   </EditItemTemplate>
55                   <ItemTemplate>
56                       <asp:CheckBox ID="CheckBox1" runat="server" />
57                   </ItemTemplate>
58               </asp:TemplateField>
59           </Columns>
60       </asp:GridView>
61       <br />
62       <asp:Button ID="claimSubmit" runat="server" OnClick="claimSubmit_Click" Text="Submit" />
63   </asp:Content>
 
0
johnkvaughan
1/26/2007 1:31:18 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

1 Replies
536 Views

Similar Articles

[PageSpeed] 33

Hi,

Yes you need to do something like this to update each record:

If cb.Checked Then

Dim str_test As String = TextBox1.Text
Dim conn As SqlConnection = New SqlConnection("Server=SHLAB-113878\\SQLEXPRESS;Database=pubs;uid=sa;pwd=**")
Dim cmd As SqlCommand = New SqlCommand("update tablename set  Runner = @UserName where keyfield = @keyfield", conn)
conn.Open
cmd.Parameters.AddWithValue("@UserName", userName )
cmd.Parameters.AddWithValue("@keyfield", keyfieldvalue)  // retrieve key field value from GridView first

Dim i As Integer = cmd.ExecuteNonQuery
conn.Dispose

 End If

Hope this helps.


NOTE:If you find my response contains a reference to a third party World Wide Web site, I am providing this information as a convenience to you.Microsoft does not control these sites and has not tested any software or information found on these sites; therefore,Microsoft cannot make any representations regarding the quality,safety, or suitability of any software or information found there.
__________________________________________________

Sincerely,
Young Fang
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. This can be beneficial to other community members reading the thread.
0
Young
1/29/2007 2:22:28 AM
Reply:

Similar Artilces:

using javascript getting value from textbox when edit button is clicked and both controls are present in gridview control
Hi All using javascript I want to get value  from textbox when edit button is clicked and both controls that is texbox and button are present in gridview control .Alok Hi aloksinha83, Please see this post: http://forums.asp.net/t/1069245.aspx Thanks,Qin Dian TangMicrosoft Online Community SupportPlease remember to mark the replies as answers if they help and unmark them if they provide no help....

Submitting Web forms fields to sql database by clicking on SUBMIT FORM and sending the form fields to email box
I have a created or designed a form to be stored in a SQL database table and at the same time when a user clicks on SUBMIT button the form fields will automatically goto the visitor email address immediately. Also i have created a database with tables for each of this forms Pls help i have over 10 forms designed but the problem of submitting them to the table database and the user email address is the challenge now.... You ned to familiarise yourself with the basics of database access in ASP.NET.  There are free tutuorials here: http://quickstarts.asp.net/QuickStartv20/aspnet/doc/da...

CheckBox in DataGrid ---> How to assign database field value to CheckBox
Hi Friends, I have a template column in DataGrid showing CheckBoxes. I wanna asign Database field value to each checkboxes in the DataGrid Column so that I could get it in the code and process the database according to the selected CheckBoxes. For ex. <ItemTemplate> <asp:CheckBox id="chkbks1" Text=<%#DataBinder.Eval(Container.DataItem , "booking_ticket")%> runat="server" /> </ItemTemplate> But it shows the text of each checkbox in DataGrid Column which is not required. I just wanna identify each CheckBox wi...

updating database on edit page after edit values in textbox field
Hi all I am having a view page with feilds like userid, username, email,and etc.....All controls are Textboxes.....All controls are disabled at view page...Data comes from database, on the bases of userlogin details...User can only view the filled by him/her during registration....I have one LinkButtion named "Edit Profile" on view page....As user clicked to Edit Profile...all controls get enabled except userid...now as user edit the details and click on save button data should get updated in the database with resoect to userid....And the problem is update query not gett...

new to .net, need help setting db values from checkbox's then retrieving value to a label control
Hi, Being new to asp.net i know this possible i just can't quite get it right!  I need a page with 5 checkbox's that when submitted sets the bit values in DB fields to checked. Then i need another page that retrieves the records of the checkboxes, but instead of having the db pre-set checkboxes on the second page i want it to turn on label web controls depending on if the check box is set.. I hope that makes sense?!! Can anyone point me in the right direction or to a suitable tutorial? Thanks in advance Ben Excellent article here.http://www.heliosfx.com...

Please..help me..How i bind the forms's fields (textboxes) to a database. And when i click submit button add a new record to my Database ...
In my mainpage a application form for users to apply.How i bind the forms's fields (textboxes) to a database. And when i click submit button add a new record to my Database ...How it do in Visual Web Developer.. please... vijaysoft:In my mainpage a application form for users to apply.How i bind the forms's fields (textboxes) to a database. And when i click submit button add a new record to my Database ...How it do in Visual Web Developer.. please... Hi vijaysoft,Based on my understanding, your want to bind a textbox control to a field of the table in database, and the value of th...

retreiving checkbox control value from database
i have already added checkbox in datagrid. in my application i want that paricular check box should be bydefault checked and unchecked depending upon values of databse suppose id. when id=1, checkbox should be checked and when id=0,checkbox should be bydefault unchecked. i dont know how to check and uncheck bydefault value.Please help. Thank you.   I thought if you data bind it, it does that for you? Was that not working? Please Mark As Answer posts that helped you."If we learn from our mistakes, I should be brilliant by now." I dont know how can I assign th...

Submit Only Controls with Modified Value to Database
I am trying to write a procedure to detect which controls have changed in a form and to submit each changed controls new value into a table with structure UserName, ControlID, Date/Time, ControlValue. A little more info...I am allowing users to submit data and then to come back and modify their anwers. For other reasons, I need to just put the modified answers into the db. They will be allowed to modify many of the previously sumbitted anwers at a time, so I need to somehow loop through all the form controls, detect which have value that have changed, and then submit them all the the data...

Problem in assinging database field value in checkbox
  Hi   I have the following code where I am retrieving values of fields in a row in dropdown, textbox and a  checkbox.   This row was previsously updated by the above controls:    However retrieving value in the checkbox is becoming a major problem as I am unable to compile the code.  In the following code block            If (prr_update_fields_retrieve(8)) = 0 Then                &n...

Problem converting CheckBox control to database field
Dear Forum, I use this same technique on other pages on other website, but for some reason I cannot get it to work on this one. I can check or uncheck the checkbox and then submit the web form, but when I go back to that entry, my checkbox still has the original value. Submitting the form did not change it. This is really bugging me because I have used the same technique in other applications with no problems! Here's the code on my ascx web control where the checkbox is:<%@ Control Inherits="MsgControl" Src="../_vb/MsgControl.vb" %> ---snip--- <br...

How do I check a checkbox control in a gridview based on the value from Database
I am trying to return rows from a table in a database and publish it on a gridview that contains checkbox control. One of the Columns in the table has either 'Y' or 'N'. I want to check the checkbox control for each row if the value of the Columns is 'Y' and have it not checked if the value is 'N'.Can somebody show me how I can get this done.Thanks in advance for your help.   In the RowDataBound eventof your GRidView u can do this to check whether the value is Y or N and then use the checked property of the check box. Remember to give...

How to see if a value entered in a textbox is present in an SQL database field?
Hello! and Help if possible!!!I am creating a booking system in ASP and C#. I have a database that stores the calendar info on some employees, including start and end dates of their current meetings.I am stuck! i am a newbie at this! ive got a pop up calendar that populates a text box with the start date selected and the same for the end date. What i need to do is pass this value to the start date field column in my sql database and iterate through the rows to see if that date already exists for that employee! if anyone has any ideas in how to do this, any help would be extremely gratefully ...

Field that controls the values that appear in this field
--_009_EEA7F24FEA5EDC42BC3FD72846A5D8F84138437CAMSPRD0711MB593_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi, Can I use the option of "Field that controls the values that appear in this= field" for non-custom fields? Thanks, Shalom. Shalom Shevach | QA Manager Comigo Ltd. O: +972- 9-771-5090 Ext. 119 | F: +972- 9-771-5091 | www.comigo.com<http= ://www.comigo.com/> E-mail: shalom.shevach@comigo.com<mailto:shalom.shevach@comigo.com> [Description: Description: Comigo]<http://comigo.com/&...

Field that controls the values that appear in this field...
SGVsbG8gRXZlcnlib2R5IQ0KDQpJJ20gd29ya2luZyBvbiBpbXBsZW1lbnRpbmcgYSBuZXcgaW5z dGFuY2Ugb2YgQlogNC40LjIgSSBuZWVkIHRvIGFkZCB0aGUgZm9sbG93aW5nIGZpZWxkczoNCg0K MS4gRGlzdHJpY3QNCjIuIFNjaG9vbCBEZXBlbmRzIG9uIERpc3RyaWN0DQozLiBUZWFjaGVyICBE ZXBlbmRzIG9uIFNjaG9vbA0KDQpJIGNvdWxkIGRvIHRoZSBSZWxhdGlvbnNoaXAgYmV0d2VlbiB0 aGVtLCBidXQgdGhlIGlzc3VlIGlzIEkgaGF2ZSBsaWtlIDUwMCsgdGVhY2hlcnMsIHNvIHdoZW4g SSB0cmllZCB0byBjcmVhdGUgYSBidWcgaXQgdGFrZXMgYSBsb25nIHRpbWUgYW5kIEkgaGF2ZSBl cnJvciBvbiB0aGUgY2hyb21lLCBJIGd1ZXNzIGlzIGZvciB0aGUgYW1vdW50IG9mIGluZm8gb24g Y2ZfdGVhY2hlciB0YWJsZS4NCg0KSXMgdGhlcmUgYSB3YXkgSSBjYW...

Web resources about - Edit a Database Field when Checkboxed Value on Submit Click - asp.net.presentation-controls

Help:Dummy edit - Wikipedia, the free encyclopedia
A dummy edit is a change in wikitext that has little or no effect on the rendered page, but saves a useful dummy edit summary. The dummy edit ...

.
An interesting patent has surfaced over at Quartz , detailing a method for exchanging unwanted gifts Amazon filed this patent application in ...

Amazon Patent Looks To Make Receiving Lousy Gifts A Thing Of The Past
... her almost entirely from the gift selection process while also leaving her completely unaware that she's been cut out in favor of a checkboxed ...

Resources last updated: 12/22/2015 4:52:17 PM