mrong
asked on
How to update records by Checkbox in ASP.NET
Greeting,
I use Repeater to display data on asp.net form. I added a checkbox field(not from the DB) in the repeater and a 'update' button outside of the repeater. Here is what I want, the user can click on the checkboxes next to each record, then click on 'update' button to run a update sql stmt for those check marked records.
the update sql stmt will always be the same like the following:
update tbl1
set field1='completed'
where ID= MyID
MyID is a field on the repeater which is the primary field(unique).
Thanks in advance.
I use Repeater to display data on asp.net form. I added a checkbox field(not from the DB) in the repeater and a 'update' button outside of the repeater. Here is what I want, the user can click on the checkboxes next to each record, then click on 'update' button to run a update sql stmt for those check marked records.
the update sql stmt will always be the same like the following:
update tbl1
set field1='completed'
where ID= MyID
MyID is a field on the repeater which is the primary field(unique).
Thanks in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Can you try changing " & Repeater1.Items(i).proposa l(i) & " to " & Repeater1.Items(i).DataKey s(i) & " instead?
Hope it helps,
Regards,
Max.
Hope it helps,
Regards,
Max.
ASKER
DreamMaster,
Do I need to set datakey to MyID somewhere?
Thanks.
Do I need to set datakey to MyID somewhere?
Thanks.
ASKER
I use the following sql stmt, it works. Now I need the sub. number '00161' with field name proposal in the repeater. Thanks.
Dim sqlText6 = "Update ae_p_pro_e set status_code='65-C' where proposal ='00161' "
Dim sqlText6 = "Update ae_p_pro_e set status_code='65-C' where proposal ='00161' "
You should be able to set that in your repeater. DataKeyField="MyID"
Hope it helps,
Regards,
Max.
Hope it helps,
Regards,
Max.
ASKER
Max,
Where and how can I set the DataKeyField in repeater?
Thank you for your patience.
Where and how can I set the DataKeyField in repeater?
Thank you for your patience.
Hi mrong,
Dreammaster,
There is no such property in repeater, its property of datagrid.
mrong,
you can try my way by binding any property of checkbox with myid column and later on take id from checkbox's property and update your row, code guideline is given in my first comment.
Regards,
Netswap.
Dreammaster,
There is no such property in repeater, its property of datagrid.
mrong,
you can try my way by binding any property of checkbox with myid column and later on take id from checkbox's property and update your row, code guideline is given in my first comment.
Regards,
Netswap.
ASKER
netswap,
in the form I have the code below as you recommended.
<td> <asp:CheckBox id="closeCase" Visible='<%# Trim(DataBinder.Eval(Conta iner.DataI tem,"statu s_code1")) = "65-C" OR Trim(DataBinder.Eval(Conta iner.DataI tem,"statu s_code1")) = "70-F" OR Trim(DataBinder.Eval(Conta iner.DataI tem,"statu s_code1")) = "75-C"%>' runat="server" ToolTip = '<%# DataBinder.Eval(container. DataItem, "proposal") %>' ></asp:CheckBox></td>
in the code-behind I have sql below.How to take the value of tooltip property as parameter for my update procedure in the sql?
Dim sqlText6 = "Update ae_p_pro_e set status_code='65-C' where proposal ='<proposal>?' "
in the form I have the code below as you recommended.
<td> <asp:CheckBox id="closeCase" Visible='<%# Trim(DataBinder.Eval(Conta
in the code-behind I have sql below.How to take the value of tooltip property as parameter for my update procedure in the sql?
Dim sqlText6 = "Update ae_p_pro_e set status_code='65-C' where proposal ='<proposal>?' "
ASKER
Thank you for your post. Below is what I have in my code-behind. Repeater1 is the name of my repeater and closeCase is the name of the checkbox. "&Repeater1.Items(i).propo
Protected Sub UpdateButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles UpdateButton.Click
Dim i
For i = 0 To Repeater1.Items.Count - 1
Dim attControl As CheckBox
Dim closeCase
attControl = Repeater1.Items(i).FindCon
If attControl.Checked = True Then
closeCase = 1
Else
closeCase = 0
End If
Dim sqlText6 = "Update ae_p_phs_e set status_code='65-COMP' where proposal ='" & Repeater1.Items(i).proposa
Dim MyOracleConn6 As New System.Data.OracleClient.O
Dim MyOracleCMD6 As New System.Data.OracleClient.O
MyOracleConn6.Open()
MyOracleCMD6.ExecuteNonQue
MyOracleConn6.Close()
Response.Redirect("Report.
Next
End Sub