Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

I am facing some problems to binding repeater in static method.

i have defined function here.

[webmethod]
public static void SearchItemformText(String SearchVal)
{


string SearchString = txtSearch.Text.ToString();
if (txtSearch.Text != null || txtSearch.Text != "")
{
using (SqlConnection con = new SqlConnection(GetCoCrsLivedata))
{
using (SqlCommand cmd = new SqlCommand("select description from item where " + "description='" + SearchVal.ToString() + "'", con))
{
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
DataTable dtnew = new DataTable();
dtnew.Load(sdr);
if (dtnew.Rows.Count > 0)
{
//rptCustomers.DataSource = dtnew;
//rptCustomers.DataBind()// I am getting

}
con.Close();
}
}
}
}</pre>



please help to achieve this one alternate solution to bind repeater in Static Web Method.

Thanks.
Posted
Comments
Richard Deeming 25-Nov-14 11:34am    
Your code is vulnerable to SQL Injection[^].

NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.

1 solution

You can't bind any server control inside the static Web Method. You can return the table to client side and bind using jQuery.

Refer one example - here[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900