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:

Wednesday, October 15, 2008

Both DataSource and DataSourceID are defined on ‘GridView1′. Remove one definition.

This is the message that you get most of the times when you try to bind your gridview or any other bindable controls to multiple Datasources.When you bind your Gridview control to an ObjectDataSource or SqlDataSource on the design surface and then you try to bind the same Gridview in the code behind using the manual coding.

The Gridview has both Datasource and DatasourceID properties.Datasource referes to the ID of another component such as SqlDataSource/XMLDataSource/AccessDataSource, whichever applies, or ObjectDataSource to act as the Datasource.


When you have the following code:


SqlDataSource1.DataBind();
GridView1.DataSource = SqlDataSource1;
GridView1.DataBind();


You'll get this error:
Both DataSource and DataSourceID are defined on ‘GridView1′. Remove one definition.


To make working,

Just add a line of code before DataBind():
GridView1.DataSourceID = string.Empty;


Now, you are fine, no more error......


Happy Programming!!