0

在页面加载时,我想显示所有字段,repeater control在文本框中输入 licenseid 时,我想显示特定的 licenceid 详细信息。

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

 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
4

1 回答 1

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()

结束子

于 2013-10-18T07:05:18.323 回答