在Repeater中搜索

时间:2013-10-18 03:52:29

标签: asp.net vb.net

在页面加载中我想显示repeater control中的所有字段以及在文本框中键入licenseid我想要显示特定的许可证详细信息。

如果我将代码放在转发器的数据源中,则第一个不起作用。在第二个中,我放置了textbox并在pageload上将其值设置为0。这是工作。但我希望两者都有效。

 SELECT * FROM License WHERE (0 = @selectAll OR LicenseID=@LicenseID) -> Not working 

 SELECT * FROM License WHERE (0 = @selectAll ) ->working

 SELECT * FROM License WHERE (LicenseID=@LicenseID)-> working

绑定代码

 Protected Sub BindRepeater()

    Dim cmd As New SqlCommand("Select * from License", con)

    If con.State = ConnectionState.Closed Then

        con.Open()

     End If

     Dim ds As New DataSet()

     Dim adp As New SqlDataAdapter(cmd)

     adp.Fill(ds)



     Repeater1.DataBind()

     con.Close()

 End Sub

1 个答案:

答案 0 :(得分:0)

Protected Sub BindRepeater(int licenseID)

string qry = "Select * from License WHERE 1=1";
if(licenseID>0) qry += " AND LicenseID=" + licenseID.ToString();

Dim cmd As New SqlCommand(qry, con)

If con.State = ConnectionState.Closed Then

    con.Open()

 End If

 Dim ds As New DataSet()

 Dim adp As New SqlDataAdapter(cmd)

 adp.Fill(ds)



 Repeater1.DataBind()

 con.Close()

End Sub