Wednesday, July 8, 2009

Autocomplete css property

<asp:textbox id="TextBox1" runat="server" autocomplete="off" width="300px">:textbox>





<%-- Make the completion list transparent and then show it --%>



<%--Cache the original size of the completion list the first time the animation is played and then set it to zero --%>





<%-- Expand from 0px to the appropriate size while fading in --%>










<%-- Collapse down to 0px and fade out --%>









Autocomplete webservice

table
country Name nvarchar(50)
country_code int

webserviceusing

using System.Collections.Generic;
using System.Web.Services;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class AutoComplete : WebService
{
public AutoComplete()
{
}

[WebMethod]
public string[] GetCountryInfo(string prefixText)
{
int count = 10;
string sql = "Select * from ECM_ITEM_MASTER Where ITEM_NAME like @prefixText";
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbEcommerceConnectionString"].ConnectionString);
SqlDataAdapter da = new SqlDataAdapter(sql, con);
da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = prefixText + "%";
DataTable dt = new DataTable();
da.Fill(dt);
string[] items = new string[dt.Rows.Count];
int i = 0;
foreach (DataRow dr in dt.Rows)
{
items.SetValue(dr["ITEM_NAME"].ToString(), i);
i++;
}
return items;
}
}

default.aspx
...............defalut.aspx.........................
<asp:TextBox ID="TextBox1" runat="server" autocomplete="off" Width="300px"></asp:TextBox>

<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" BehaviorID="AutoCompleteEx"
runat="server" EnableCaching="true"
CompletionInterval="200" CompletionListCssClass="autocompleteplus_completionListElement"
CompletionListItemCssClass="autocompleteplus_listItem" CompletionListHighlightedItemCssClass="autocompleteplus_highlightedListItem"
DelimiterCharacters=";, :"
MinimumPrefixLength="1" ServiceMethod="GetCountryInfo"
ServicePath="AutoComplete.asmx"
TargetControlID="TextBox1">


<Animations>


<OnShow>

<Sequence>
<%-- Make the completion list transparent and then show it --%>

<OpacityAction Opacity="0" />

<HideAction Visible="true" />

<%--Cache the original size of the completion list the first time the animation is played and then set it to zero --%>
<ScriptAction Script=" // Cache the size and setup the initial size var behavior
= $find('AutoCompleteEx'); if (!behavior._height) { var target = behavior.get_completionList();
behavior._height = target.offsetHeight - 2; target.style.height = '0px'; }" />
<%-- Expand from 0px to the appropriate size while fading in --%>

<Parallel Duration=".4">


<FadeIn />

<Length PropertyKey="height"
StartValue="0" EndValueScript="$find('AutoCompleteEx')._height" /> </Parallel>
</Sequence> </OnShow> <OnHide>
<%-- Collapse down to 0px and fade out --%>
<Parallel Duration=".4">


<FadeOut />


<Length PropertyKey="height"
StartValueScript="$find('AutoCompleteEx')._height" EndValue="0" />

</Parallel>
</OnHide> </Animations> </cc1:AutoCompleteExtender>

Monday, July 6, 2009

Cascading Extender dropdownlist

Database REQUIREMENT
Table EIM_COUNTRY
COUNTRY_CODE INT
COUNTRY_NAME NVARCHAR(100)
ISACTIVE BIT
2)EIM_STATE
STATE_CODE INT
STATE_NAME NVARCHAR(100)
COUNTRY_CODE INT
ISACTIVE BIT

........................................next........................
ADD CascadingDataService.asmx
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Data;
using AjaxControlToolkit;

///
/// Summary description for CascadingDataService
///

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class CascadingDataService : System.Web.Services.WebService
{

string conString = System.Configuration.ConfigurationManager.ConnectionStrings["dbEcommerceConnectionString"].ToString();

public CascadingDataService()
{

//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public CascadingDropDownNameValue[] GetCountry(string knownCategoryValues, string category)
{
SqlConnection sqlConn = new SqlConnection(conString);
sqlConn.Open();
SqlCommand sqlSelect = new SqlCommand("SELECT * FROM ECM_COUNTRY", sqlConn);
sqlSelect.CommandType = System.Data.CommandType.Text;
SqlDataAdapter sqlAdapter = new SqlDataAdapter(sqlSelect);
DataSet myDataset = new DataSet();
sqlAdapter.Fill(myDataset);
sqlConn.Close();
//dsCarsTableAdapters.CarsTableAdapter makeAdapter = new dsCarsTableAdapters.CarsTableAdapter();
//dsCars.CarsDataTable makes = makeAdapter.GetAllCars();
List values = new List();
foreach (DataRow dr in myDataset.Tables[0].Rows)
{
string name = (string)dr["COUNTRY_NAME"];
int code = (int)dr["COUNTRY_CODE"];
values.Add(new CascadingDropDownNameValue(name, code.ToString()));
}
return values.ToArray();
}
[WebMethod]
public AjaxControlToolkit.CascadingDropDownNameValue[] GetStates(string knownCategoryValues, string category)
{
StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
int makeId;
if (!kv.ContainsKey("name") || !Int32.TryParse(kv["name"], out makeId))
{
return null;
}
SqlConnection sqlConn = new SqlConnection(conString);
sqlConn.Open();
SqlCommand sqlSelect = new SqlCommand("SELECT * FROM ECM_STATES where COUNTRY_CODE = @COUNTRY_CODE", sqlConn);
sqlSelect.CommandType = System.Data.CommandType.Text;
sqlSelect.Parameters.Add("@COUNTRY_CODE", SqlDbType.Int).Value = makeId;
SqlDataAdapter sqlAdapter = new SqlDataAdapter(sqlSelect);
DataSet myDataset = new DataSet();
sqlAdapter.Fill(myDataset);
sqlConn.Close();

List cascadingValues = new List();

foreach (DataRow dRow in myDataset.Tables[0].Rows)
{
string StateID = dRow["STATE_CODE"].ToString();
string StateName = dRow["STATE_NAME"].ToString();
cascadingValues.Add(new CascadingDropDownNameValue(StateName, StateID));
}

return cascadingValues.ToArray();
}
}
......defalut.aspx














   <asp:dropdownlist id="ddlMakes" runat="server" width="240px">
<cc1:cascadingdropdown id="ddlMakes_CascadingDropDown" runat="server"
enabled="True"
category="name"
prompttext="Choose a Country...."
loadingtext="Please wait ..."
servicepath="CascadingDataService.asmx"
servicemethod="GetCountry"
targetcontrolid="ddlMakes">
</cc1:cascadingdropdown>
</asp:dropdownlist>



         <asp:dropdownlist id="ddlModels" runat="server" width="240px">
<cc1:cascadingdropdown id="ddlModels_CascadingDropDown" runat="server" enabled="True"
parentcontrolid="ddlMakes"
category="StateName"
servicepath="CascadingDataService.asmx"
servicemethod="GetStates"
targetcontrolid="ddlModels"
prompttext="Choose a State...."
loadingtext="Please wait ...">
</cc1:cascadingdropdown>
</asp:dropdownlist>







Saturday, July 4, 2009

LINQ Insert Records - ASP.NET

country table
COUNTRY_NAME nvarchar(80)
COUNTRY_SHORT_NAME nchar(3)
COUNTRY_SORT_ORDER float
COUNTRY_VALID bit
code behind page
protected void Button1_Click(object sender, EventArgs e)
{
ShoppingDataContext db = new ShoppingDataContext();
ECM_COUNTRY objCountry = new ECM_COUNTRY
{
COUNTRY_NAME =txtCountryName.Text.Trim(),
COUNTRY_SHORT_NAME=txtshortName.Text.Trim(),
COUNTRY_SORT_ORDER =Convert.ToDouble(txtSortOrder.Text.Trim()),
COUNTRY_VALID =Convert.ToBoolean(chkIsActive.Checked)
};
db.ECM_COUNTRies.InsertOnSubmit(objCountry);
db.SubmitChanges();
Response.Redirect(Request.RawUrl);
txtCountryName.Text = "";
txtshortName.Text = "";
txtSortOrder.Text = "";
chkIsActive.Checked = false;
}
http://blogsiteslist.com