2014年7月13日 星期日

[RESOLVED] Gridview Update whit radiobutton


Hi, 


I Have a gridview :









 





and:


        If e.CommandName = "select" Then
TextBox4.Text = e.CommandArgument.ToString()


For Each row As GridViewRow In GridView1.Rows

Dim constr As String = ConfigurationManager.ConnectionStrings("starfairConnectionString").ConnectionString
Dim con As New SqlConnection(constr)
Dim cmd As New SqlCommand("firpicup1", con)
cmd.CommandType = CommandType.StoredProcedure
Dim RowIndex As Integer = Convert.ToInt32(e.CommandArgument)
cmd.Parameters.Add(New SqlParameter("@picid", TextBox4.Text))
Dim rb As RadioButton = DirectCast(row.FindControl("RadioButton1"), RadioButton)
cmd.Parameters.Add(New SqlParameter("@main1", "1"))
Dim dr As SqlDataReader
con.Open()
dr = cmd.ExecuteReader()
GridView1.DataBind()
Next
End If

I want when radio button checked, current row "main1" field =1 and in the other rows"main1" field =0,


how to change the above code?












No one to help me?

hi,


You can't use rowcommand event in radiobutton . and we also can't use checkedchange event .Even if defind groupname of this radiobutton , but in different row the name in html code of this radiobutton is different .you can press F12 to observed the radiobutton's
name .you will get such as the below :


name="GridView2$ctl02$abc" value="RadioButton1" />

name="GridView2$ctl03$abc" value="RadioButton1" />

Because the name is different ,so the checkedchanged event can't trigger .


to you purpose .I suggest use linkbutton or use checkbox .


Hope this helps


 


 


 



Thanks. For checkbox how i do?

hi,


This tutorial looks at how to add a column of check boxes to a GridView control to provide the user with an intuitive way of selecting multiple rows of the GridView.


http://www.asp.net/web-forms/tutorials/data-access/enhancing-the-gridview/adding-a-gridview-column-of-checkboxes-cs


if you need to change row value or something else by checkbox changed event  , you can use Jquery ajax  to trigger webmethod in webmethod .


http://stackoverflow.com/questions/348689/jquery-ajax-with-asp-net-webmethod-returning-entire-page


Hope this helps


沒有留言:

張貼留言