2014年7月13日 星期日

[RESOLVED] RadioButton in Gridview


Hi,


I have table whit field: "picid" , and a gridview whit radiobutton:








 




In gridview, i want only one radiobutton is checked,


and when click the other radiobutton, current record "picid" field is 1 and other records picid is 0, (table Update)


I want in blew code:


update pic set picid=1 where radiobutton selected and other records of gridviwe --> picid=0


If e.CommandName = "select" Then
Dim constr As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
Dim con As New SqlConnection(constr)
Dim cmd As New SqlCommand("picup", con)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add(New SqlParameter("@picid", e.CommandArgument.ToString()))
Dim dr As SqlDataReader
con.Open()
dr = cmd.ExecuteReader()
GridView1.DataBind()
End If

How i do?


Thank you for your attention...





anuj_koundal



Use groupname property to group them.

Refrence: http://www.codingfusion.com/Post/Write-a-program-to-list-your-favourate-colors-usin







This is not solve my problem,


i use only one radiobutton in gridview ... and  ...



you have to fire SelectCommand from your grid, to properly catch the grid-selection changed event. and you should use GroupName properly as well,




Please send me more code for this, if possible. 1. I want only 1 radiobutton checked in every time. 2. I want when radiobutton checked: picid field of current record set =1 and picid filed other records set=0

For your first requirement only one radio button is checked : 







groupname="abc" ID="RadioButton1" runat="server" Checked='<%# Eval("picid") %>' />
 




For your second requirement you have to write your own code in codebehind.If you can provide your storedprocedure may be I can help more.



To check one radio try this


    protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
RadioButton rb = (RadioButton)row.FindControl("RadioButton1");
rb.Checked = false;
}
RadioButton currentrb = (RadioButton)sender;
currentrb.Checked = true;
}









oned_gk



To check one radio try this
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
RadioButton rb = (RadioButton)row.FindControl("RadioButton1");
rb.Checked = false;
}
RadioButton currentrb = (RadioButton)sender;
currentrb.Checked = true;
}







Thank you, this is work,


for update rows how i do? in gridview 



I want "picid" of selected row (radiobutton checked=true) = 1 and other row shown in gridview => picid=0,


please help me,



I want try this, but thi is not work:








 





and:


        If e.CommandName = "select" Then
TextBox4.Text = e.CommandArgument.ToString()
For Each row As GridView 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", rb.Checked))
Dim dr As SqlDataReader
con.Open()
dr = cmd.ExecuteReader()
GridView1.DataBind()
Next







沒有留言:

張貼留言