在页面加载中我想显示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
答案 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