Reputation: 769
I have 4 dropdown list in my grid view. I want them to be loaded using webservices. Is it possible to do so? How to accomplish this?
Upvotes: 1
Views: 858
Reputation: 689
Yes You can populate using Webservices. You can try like this. I havent tried this.
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["Connection"].ToString());
[WebMethod]
public DataSet DDLList()
{
conn.Open();
SqlCommand ad1 = new SqlCommand("select Id,ValueText from Table", conn);
SqlDataAdapter adapt = new SqlDataAdapter(ad1);
DataSet ds = new DataSet();
adapt.Fill(ds);
conn.Close();
return ds;
}
In the aspx.cs Page, You can call this webmethod and return DataSet.
Public DataSet FillDDl()
{
UrService.Service test = new UrService.Service();
DataSet ds = new DataSet();
ds = test.DDLList();
return ds;
}
In the aspx markup, You can call the FillDDl
method.
<asp:DropDownList ID="ddl" DataSource='<%# FillDDl() %>' DataTextField="ValueText" DataValueField="Id" runat="server"></asp:DropDownList>
Upvotes: 1