Tuesday, October 28, 2008

Creating A-Z lists

If you want to creat A-Z lists in a Repeater control and implement so that people can click that charater and get value from database which start from that clicked charater.

ASPX Page:


Aspx.cs Page:
protected void Repeater1_RowCreated(object sender, RepeaterItemEventArgs e)
{
//Create A-Z listArrayList ab = new ArrayList();for (int i = 0; i < datasource =" ab;Repeater2.DataSourceID">

protected void Repeater1_RowCommand(object sender, RepeaterCommandEventArgs e)
{
if (e.CommandName.Equals("AlphaPaging"))
{
//convert ASCII value to char/string.i.e. A=>65

int index;
index = Convert.ToInt32(e.CommandArgument);
String abc = Char.ConvertFromUtf32(index);
String sql = "select Title,Scope,CollectionAbstract,CollectionIdentifier" +
" from tblCollections_Collections" +" where RepositoryID in( " + repository + " ) and Title LIKE '" + abc + "%'";

Response.Write(sql);
SqlConnection conn = new SqlConnection(DataAccess.GetConnectionString());
conn.Open();
SqlDataAdapter ad = new SqlDataAdapter(sql, conn);
ad.SelectCommand = new SqlCommand(sql, conn);
DataSet ds = new DataSet();
ad.Fill(ds);

Repeater1.DataSource = ds;
Repeater1.DataSourceID = string.Empty;
Repeater1.DataBind();
conn.Close();
}
}
}

Result:

No comments:

Post a Comment

Highly Appreciated your comments