<asp:TextBox ID="txtAuto" runat="server"></asp:TextBox>
<div id="Panel">
</div>
<asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" CompletionInterval="0"
CompletionListElementID="Panel" CompletionSetCount="12" EnableCaching="true"
MinimumPrefixLength="1" ServiceMethod="GetProductList"
ShowOnlyCurrentWordInCompletionListItem="true" TargetControlID="txtAuto"
>
</asp:AutoCompleteExtender>
<%-- <asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="txtAuto"
MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="1" CompletionInterval="1000" ServiceMethod="GetProductList" >
</asp:AutoCompleteExtender>--%>
</br>
<asp:Button ID="btnSubmitt" runat="server" Text="Submitt" OnClick="btnSubmitt_Click" />
</br>
<asp:Label ID="lblLocation" runat="server"></asp:Label></br>
<asp:Label ID="lblLevel" runat="server"></asp:Label>
</div>
........................................................
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static string[] GetProductList(string prefixText)
{
string connString = "";
string path = @"C:\Test\Company.xls";
//Connection String to Excel Workboo
//if (strFileType.Trim() == ".xls")
//{
// connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";
connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
//}
//else if (strFileType.Trim() == ".xlsx")
//{
// connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
//}
// string query = "SELECT [Company] FROM [Sheet1$] where Company like '" + prefixText + "'";
string query = "SELECT [Company] FROM [Sheet1$] where Company like '" + prefixText + "'+'%'";
OleDbConnection conn = new OleDbConnection(connString);
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
else
{
}
OleDbCommand cmd = new OleDbCommand(query, conn);
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = ds.Tables[0];
List<string> txtProductName = new List<string>();
String dbValues;
foreach (DataRow row in dt.Rows)
{
dbValues = row["Company"].ToString();
dbValues = dbValues.ToLower();
txtProductName.Add(dbValues);
}
return txtProductName.ToArray();
}
protected void btnSubmitt_Click(object sender, System.EventArgs e)
{
string connString = "";
string path = @"C:\Test\Company.xls";
//Connection String to Excel Workboo
//if (strFileType.Trim() == ".xls")
//{
// connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";
connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
//}
//else if (strFileType.Trim() == ".xlsx")
//{
// connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
//}
// string query = "SELECT [Company] FROM [Sheet1$] where Company like '" + prefixText + "'";
string query = "SELECT [Location],[Level] FROM [Sheet1$] where Company = '" + txtAuto.Text.Trim() + "'";
OleDbConnection conn = new OleDbConnection(connString);
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
else
{
}
OleDbCommand cmd = new OleDbCommand(query, conn);
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
lblLocation.Text = Convert.ToString(ds.Tables[0].Rows[0]["Location"]);
lblLevel.Text = Convert.ToString(ds.Tables[0].Rows[0]["Level"]);
}
}
<div id="Panel">
</div>
<asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" CompletionInterval="0"
CompletionListElementID="Panel" CompletionSetCount="12" EnableCaching="true"
MinimumPrefixLength="1" ServiceMethod="GetProductList"
ShowOnlyCurrentWordInCompletionListItem="true" TargetControlID="txtAuto"
>
</asp:AutoCompleteExtender>
<%-- <asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="txtAuto"
MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="1" CompletionInterval="1000" ServiceMethod="GetProductList" >
</asp:AutoCompleteExtender>--%>
</br>
<asp:Button ID="btnSubmitt" runat="server" Text="Submitt" OnClick="btnSubmitt_Click" />
</br>
<asp:Label ID="lblLocation" runat="server"></asp:Label></br>
<asp:Label ID="lblLevel" runat="server"></asp:Label>
</div>
........................................................
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static string[] GetProductList(string prefixText)
{
string connString = "";
string path = @"C:\Test\Company.xls";
//Connection String to Excel Workboo
//if (strFileType.Trim() == ".xls")
//{
// connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";
connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
//}
//else if (strFileType.Trim() == ".xlsx")
//{
// connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
//}
// string query = "SELECT [Company] FROM [Sheet1$] where Company like '" + prefixText + "'";
string query = "SELECT [Company] FROM [Sheet1$] where Company like '" + prefixText + "'+'%'";
OleDbConnection conn = new OleDbConnection(connString);
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
else
{
}
OleDbCommand cmd = new OleDbCommand(query, conn);
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = ds.Tables[0];
List<string> txtProductName = new List<string>();
String dbValues;
foreach (DataRow row in dt.Rows)
{
dbValues = row["Company"].ToString();
dbValues = dbValues.ToLower();
txtProductName.Add(dbValues);
}
return txtProductName.ToArray();
}
protected void btnSubmitt_Click(object sender, System.EventArgs e)
{
string connString = "";
string path = @"C:\Test\Company.xls";
//Connection String to Excel Workboo
//if (strFileType.Trim() == ".xls")
//{
// connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";
connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
//}
//else if (strFileType.Trim() == ".xlsx")
//{
// connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
//}
// string query = "SELECT [Company] FROM [Sheet1$] where Company like '" + prefixText + "'";
string query = "SELECT [Location],[Level] FROM [Sheet1$] where Company = '" + txtAuto.Text.Trim() + "'";
OleDbConnection conn = new OleDbConnection(connString);
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
else
{
}
OleDbCommand cmd = new OleDbCommand(query, conn);
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
lblLocation.Text = Convert.ToString(ds.Tables[0].Rows[0]["Location"]);
lblLevel.Text = Convert.ToString(ds.Tables[0].Rows[0]["Level"]);
}
}
0 comments:
Post a Comment