[Csharp]
Public void GetDataListData (string standardclass, string toothtypeBig, int I)
{
DataTable dt = bindData (standardclass, toothtypeBig );
DataList d = new DataList ();
D. ID = "dlstTest ";
D. ItemTemplate = new mycolum( "litData", 200 );
D. RepeatColumns = 5;
D. RepeatDirection = RepeatDirection. Horizontal;
D. ItemDataBound + = new DataListItemEventHandler (d_ItemDataBound );
D. DataSource = dt;
D. DataBind ();
HtmlGenericControl div = new HtmlGenericControl ("div ");
Div. Attributes. Add ("class", "ProductIntroList ");
If (I = 0)
Div. Style. Add ("display", "block ");
Else
Div. Style. Add ("display", "none ");
Div. Controls. Add (d );
This. divList. Controls. Add (div );
}
Private void d_ItemDataBound (object sender, System. Web. UI. WebControls. DataListItemEventArgs e)
{
Literal t;
If (e. Item. ItemType = ListItemType. Item | e. Item. ItemType = ListItemType. AlternatingItem)
{
T = (Literal) e. Item. FindControl ("litData ");
If (t! = Null)
{
String ulstring = string. Format (@ "<ul> <li> <a class = 'imageblock' href = 'productinfor. aspx? {0} '>
</a>
<A class = 'textblock' href = 'productinfor. aspx? {0} '> {2}-{3} </a> </li>
</Ul> ", (DataRowView) e. item. dataItem ). row ["Url"]. toString (), (DataRowView) e. item. dataItem ). row ["ImageUrl"]. toString (), (DataRowView) e. item. dataItem ). row ["Name"]. toString (), (DataRowView) e. item. dataItem ). row ["CDescription"]. toString ());
T. Text = ulstring;
}
}
}
Public DataTable bindData (string _ standardclass, string _ toothtypebig)
{
This. divShopNull. Visible = false;
Try
{
String SQL = @ "select DISTINCT Name, CDescription, StandardClass, Groove, HeadType, ToothTypeBig from ba_ShellTrumpet where 1 = 1 ";
If (_ standardclass! = "")
{
SQL + = "and StandardClass = '" + _ standardclass + "'";
}
If (_ toothtypebig! = "")
SQL + = "and ToothTypeBig = '" + _ toothtypebig + "'";
SQL + = "order by Name ";
DataTable standard = BLL. GetDataTable (SQL );
If (! CommonClass. DTRow. CheckDtIsEmpty (standard ))
{
Standard. Columns. Add ("Url", typeof (string ));
Standard. Columns. Add ("ImageUrl", typeof (string ));
For (int I = 0; I <standard. Rows. Count; I ++)
{
// StandardClass = {0} & Name = {1} & CDescription = {2}
Standard. rows [I] ["Url"] = "StandardClass =" + standard. rows [I] ["StandardClass"]. toString () + "& Name =" + standard. rows [I] ["Name"]. toString () + "& CDescription =" + standard. rows [I] ["CDescription"]. toString () + "& Groove =" + standard. rows [I] ["Groove"]. toString () + "& HeadType =" + standard. rows [I] ["HeadType"]. toString () + "& ToothTypeBig =" + standard. rows [I] ["ToothTypeBig"]. toString ();
Standard. Rows [I] ["ImageUrl"] = ImageUrl (standard. Rows [I] ["Name"]. ToString ());
}
Return standard;
}
Else
{
This. divShopNull. Visible = true;
Return null;
}
}
Catch (Exception ex)
{
Throw;
Return null;
}
}
Public class MyColumn: ITemplate
{
Private string pControlName; // Control name
Private int pWidth; // control width
Public MyColumn (string ControlName, int Width)
{
PControlName = ControlName;
PWidth = Width;
}
Public void InstantiateIn (Control container)
{
Literal h = new Literal ();
H. ID = pControlName;
Container. Controls. Add (h );
}
}
Public string ImageUrl (string name)
{
If (name = "")
Return "no_pic.jpg ";
String imagename = "imgProduct \" + name + ". jpg ";
String path = System. Web. HttpContext. Current. Server. MapPath (imagename); // WebHelper. GetSiteUrl () + "\" + imagename;
If (System. IO. File. Exists (path ))
{
Return name + ". jpg ";
}
Return "no_pic.jpg ";
}