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!!

Monday, September 15, 2008

SQL Trigger-To check the data at Notes Field

I am going to write a Trigger to validate the column field in the table name 'LenderAddressAll' and the column name is 'Notes'.My trigger checks the data entered into that column and if it valid that's ok otherwise it'll pop up 'error'.The data format should be 000 xxxxxx.First three numbers should be 0's and then empty space and after that it should be any six digits(Total varchar(10)).

Create trigger tri
on
LenderAddressesALL
after
insert
AS
select
lender.Notes from LenderAddressesALL lender join inserted i on i.Notes = lender.Notes
where i.Notes is NOT null
declare @temp varchar(10)
select @temp = Notes from inserted

if(len(@temp) = 10 and substring(@temp,1, 4) = '000 '
and cast(substring(@temp, 5, 10) as int) > 0
and cast(substring(@temp, 5, 10) as int) <>
return
else
begin print 'error!!!!'
RAISERROR ('Error!!', 16, 1)
rollback transaction
end
GO

Happy Programming!!