Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

bordering the selected picture 1

Status
Not open for further replies.

nnmmss72

Programmer
May 14, 2006
110
IR
i have a aspx page which retirve n pictures from a path and put them in row, so the page is scrolled in horizantaly. now i want to do something for following

1- by clicking on a picture the whole page and the parent page should be refresh
2- this picture(selected one) should have a border around it
3-and the page should be scrolled up to the selected picture
(something like name anchor)

number one has been done, but would please help me for number 2 and 3.

Thanks
 
Item #2 could be done by changing the CSSClass of the relevant image and have that class set to something like "border: 1px solid Red"

Item #3 can be done in many ways. SmartNavigation is the built-in method but it has many problems so I suggets searching this forum for other methods as this has been discussed many times.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
what control are you using? Repeater, Datalist?

if a datalist, you can add this, to get the class applied...

<SelectedItemStyle CssClass="WhatCA8MSMSaid" />

(class)
.WhatCA8MSMSaid
{
border: 1px solid Red;
}

2.0 has the SetFocus function built in now, so since you are posting back, at the end your onSelectedIndexChanged event, (if datalist), just add

SetFocus(e.Item.FindControl("myAspImage"))

you'll have to cast to whatever control it is if you use c#
SetFocus((ImageButton)(e.Item.FindControl("myAspImage"));

that should get you close enough of a focus, if not (too far left or right) you can make other adjustments, but without a layout, its hard to give advice on that one.
 
I have this on my aspx page

<asp:Repeater id="Repeater2" runat="server">
<HeaderTemplate>
<table><tr>
</HeaderTemplate>
<ItemTemplate>
<td align="middle">
<a href='javascript:checkurl(<%# DataBinder.Eval(Container.DataItem,"Prod_id")%>,<%# DataBinder.Eval(Container.DataItem,"model_id")%>)'>
<img src='images/<%# DataBinder.Eval(Container.DataItem,"fullimg")%>' border=0 style="BORDER-RIGHT: white 0px solid; BORDER-TOP: white 0px solid; BORDER-LEFT: white 0px solid; BORDER-BOTTOM: white 0px solid" id='<%# DataBinder.Eval(Container.DataItem,"fullimg")%>'></a>
<br>
</td>
</ItemTemplate>
<FooterTemplate>
</tr> </table>
</FooterTemplate>
</asp:Repeater>


and also this one in behind code

private void Page_Load(object sender, System.EventArgs e)
{
String Qid=Request.QueryString["id"];
Qid="5";
String SelCmd="Select * from TblFRModel Where prod_id=@id";
SqlConnection myConnection=new SqlConnection(ConnectionInfo);
SqlCommand myCommand=new SqlCommand(SelCmd,myConnection);
myCommand.Parameters.Add(new SqlParameter("@id",SqlDbType.Int));
myCommand.Parameters["@id"].Value=System.Convert.ToInt32(Qid);
myCommand.Connection.Open();
SqlDataReader dr=myCommand.ExecuteReader();
Repeater2.DataSource=dr;
Repeater2.DataBind();
dr.Close();
myCommand.Connection.Close();
}

and this Itemdatabind

private void Repeater2_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e) {
if( (e.Item.ItemType == ListItemType.Item))
{
DbDataRecord dbr = (DbDataRecord)e.Item.DataItem;
if( Convert.ToString(DataBinder.Eval(dbr, "fullimg")) == "USA" )
/***********/
heer i should access to style border of image to make a border for it, which i don't know what is the syntax
/***********/
}
}


and the second qesution it doesn't enter the ItemDataBound Method

This is the InitializeComponent Method
private void InitializeComponent()
{
this.Repeater2.ItemDataBound += new System.Web.UI.WebControls.RepeaterItemEventHandler(this.Repeater2_ItemDataBound);
this.Load += new System.EventHandler(this.Page_Load);
}

but it doesn't enter the Item data bound?
 
well actually i have problem on accessing the border of image. let me explain the case more in detail.
1- the pictures are created in Repeater section by asp:Image or evenn could be with img Tag
2- so the name of the every image is taken from a field in table
3- all of the image should have border=0 except for the selected one. so i did so

private void Repeater1_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
String Mid;
if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType !=ListItemType.AlternatingItem)
return;
System.Data.Common.DbDataRecord rec = (System.Data.Common.DbDataRecord)
e.Item.DataItem;
Mid=Request.QueryString["Mid"]; /*this is the id of selected
if ((String)rec["model_id"]==Mid)
/***************/
Here i should make the border of selected image to a number
but how can access the border attribute (in style ) or as a property?
i did following ,but it is wrong
e.Item.FindControl(rec["fullimg"]).BorderWidth=5;


 
I think you need to do the e.Item.FindControl(rec["fullimg"]) and cast it to an image. Then use the attributes.add() method.
 
but how can defibe a variable as image ? i mean is this right?

Image imagevar;
imagevar=(Image)e.Item.FindControl(rec["fullimg"])

it says "iamge is ambiuos reference
 
Its an HTMLImage

you need to have a runat="server" on the HTML control to be able to access it via code behind

i dont think you should have a dynamic id tag, as .net will render the control with a unique id by itself, so you might need to rework this a bit for your complete solution.

couple of cleanup tips
Code:
<img src='<%# DataBinder.Eval(Container.DataItem,"fullimg","images/{0}")%>' style="border: white 0px solid;" id="myHTMLImage" runat="server" />

accessing from codebehind
Code:
if (e.Item.ItemType == ListItemType.SelectedItem)
{
    HtmlImage myImg = ((HtmlImage)(e.Item.FindControl("myHTMLImage")));
    myImg.Attributes.Add("style","border: solid 1px red;");
}

Let .net do some of the work for you thats built in
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top