根据单选按钮搜索产品,然后选择 [英] search the products according to the radio button select

查看:62
本文介绍了根据单选按钮搜索产品,然后选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下午好朋友,
我正在Asp.net 3.5框架Visual Studio 2008中开发网站.
我要实现的是,我的网页中没有单选按钮和1个搜索按钮,我希望客户根据选择的单选按钮搜索产品,但没有触发任何事件.请帮助我.
最好的问候,
Santosh More

Good Afternoon friends,
I am developing website in Asp.net 3.5 framework visual studio 2008.
What I want to achieve is that I have no of radio buttons and 1 search button in my web page I want the client to search the products according to the radio button select, but none of its event is getting fired.please help me.
Best Regards,
Santosh More

推荐答案

在radioButtonList中写入AutoPostBack ="True",而不是"SelectedIndexChanged"事件将触发.
如果要查找所选单选按钮的值,请输入
In the radioButtonList write AutoPostBack = "True" than ''SelectedIndexChanged'' event will fire.

If you want to find the value of the selected radio button then write
RadioButtonList1.SelectedValue;


<asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True">
        <asp:ListItem>Search1</asp:ListItem>
        <asp:ListItem>Search2</asp:ListItem>
        <asp:ListItem>Search3</asp:ListItem>
    </asp:RadioButtonList>
    <asp:Button ID="Button6" runat="server" style="height: 26px" Text="Button" />




代码将如下所示:




Code will be like this:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
If RadioButtonList1.Text = "Search1" Then
Search1() ''call function for search1
 Else If RadioButtonList1.Text = "Search2" Then
Search2 ''call function for search2
 Else If RadioButtonList1.Text = "Search3" Then
Search3() ''call function for search3
End If
  End Sub

Private Sub Search1()
''search according to the condition
End Sub

Private Sub Search2()
''search according to the condition
End Sub

Private Sub Search3()
''search according to the condition
End Sub


像这样尝试

Try Like This

<asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True">
        <asp:ListItem>Naveen</asp:ListItem>
        <asp:ListItem>Kumar</asp:ListItem>
        <asp:ListItem>aaaa</asp:ListItem>
    </asp:RadioButtonList>
    <asp:Button ID="Button6" runat="server" style="height: 26px" Text="Button" />



在CS中:



IN CS:

Protected Sub Button6_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button6.Click
      con = New SqlConnection(ConfigurationManager.ConnectionStrings("con").ConnectionString)
      If con.State = ConnectionState.Closed Then
          con.Open()
      End If

      da = New SqlDataAdapter("select * from sample where name='" + RadioButtonList1.SelectedItem.Text + "'", con)
      ds = New DataSet()
      da.Fill(ds)
      GridView1.DataSource = ds
      GridView1.DataBind()
  End Sub


这篇关于根据单选按钮搜索产品,然后选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆