Hi! I have two table Fruit and Person.
Id Name
1
|
Apple
|
2
|
Charry
|
3
|
Orange
|
4
|
Melon
|
5
|
Watermelon
|
Person
But I want save Personid from drop down list and fruit from fruit table into person.
<asp:DropDownList ID="ddl" runat="server" multiple="multiple" Height="22px" Width="230px">
<asp:ListItem>Sadriddin</asp:ListItem>
<asp:ListItem>Rustam</asp:ListItem>
<asp:ListItem>Nurullo</asp:ListItem>
<asp:ListItem>Firuz</asp:ListItem>
<asp:ListItem>Yakub</asp:ListItem>
<asp:ListItem>Asror</asp:ListItem>
</asp:DropDownList>
For fruit need use autocomplete textbox with this method.
Search.ashx code:
<%@ WebHandler Language="C#" Class="Search_CS" %>
using System;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Web.Script.Serialization;
public class Search_CS : IHttpHandler {
public void ProcessRequest(HttpContext context)
{
string UserData = System.Configuration.ConfigurationManager.AppSettings.Get("Base");//connection
string prefixText = context.Request.QueryString["term"];
using (SqlConnection conn = new SqlConnection(UserData))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "select * from Fruits where name like @SearchText + '%'";
cmd.Parameters.AddWithValue("@SearchText", prefixText);
cmd.Connection = conn;
List<string> customers = new List<string>();
conn.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
customers.Add(string.Format("{0}-{1}", sdr["name"], sdr["Id"]));
}
}
conn.Close();
context.Response.Write(new JavaScriptSerializer().Serialize(customers));
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
All code and html I shared on top.
For example:
Id
|
PersonId
|
Fruit
|
1
|
1,2
|
Apple
|
2
|
1,3
|
Orange
|