Link to home
Start Free TrialLog in
Avatar of steve_mick972
steve_mick972

asked on

Displaying Arrow Images dynamically....

Hi,
 
   I have a Asp.net Page, which contains a UserControl and that UserControl loads some employee names as link buttons from the database, and attaching one eventhandler to all the LinkButtons which will do some stuff according to the selected employee ID and displays some information on that Asp.net Page....

Now the problem is when Iam displaying all the employees names Iam also displaying a blackarrow before each employee name, now when user clicks on one particular employee name I want to display the red arrow, instead of blackarrow only for that particular employee name, rest all must display black arrow... I tried some ways, but I failed to achieve the result... AnyIdeas and if possible sample code would be greatly appreciable....
Please let me know if Iam too vague in explaining...
Avatar of caner_elci
caner_elci

You can do that in client-side.. using Javascript.. if this is what you want, let me know so I give you an example...
is this causing a postback which shows the details ?

If so its very easy on either side (javascript or codebehind)
is this causing a postback which shows the details ?

If so its very easy on either side (javascript or codebehind)
Avatar of steve_mick972

ASKER

Hi,
  caner_elci, Iam ready to use some javascript, but Iam writing displaying those employeenames using linkbuttons in codebehind, and I know I can append JavaScript in Codebehind, can you please provide me some javascript code which will do that for me, if possible please provide me the javascript code so that I can easily embed that into codebehind..

 gregoryyoung, Iam really not sure which one your asking whether it is causing postback r not??, but I'll explain you wht exactly going on (sorry for being so dumb)... Iam writing a database query which will get me all the employee names and looping through the Reader and creating a linkbutton and the tex of the linkbutton is the employee name and attaching all the link buttons to one eventhandler function, before attaching this link button to a table cell (to place the linkbutton at appropriate place on the page) Iam also attaching a black arrow Image to the table cell... and all this is done in PageLoad() event of the page. this is wat happening in the page, I want a mechanism to check which linkbutton is clicked and accordingly I want to place a red arrow instead of black arrow...


Thank You,
Steve
Hi Steve,

Of course, I can write a sample code for you.. But I need to see your code.. can you please paste some code from your aspx file? Especially, the parts those you create buttons.. So I can write a few Javascript functions to enable/disable them...

Caner

public void Page_Load()
{
  //after opening the database connection and getting the data into the Reader Object
 // this is how my code looks like....
  while(Reader.Read())
  {
   //create a link button for each employee
    LinkButton lnkEmp = new LinkButton();
   // set linkbutton properties
    lnkEmp.ID = Reader["EmpID"].ToString();
    lnkEmp.Text = Reader["EmpName"].ToString() + "<br>";
  //set linkbutton clickevent handler
    lnkEmp.Click += new EventHandler(this.ProcessClick);

   // create a row and cell to attach Image and linkbutton to the page
    HtmlTableRow tblRowEmp = new HtmlTableRow();
    HtmlTableCell tblCellEmp = new HtmlTableCell();
    HtmlTableCell tblCellBarrow = new HtmlTableCell();
   
   //create a HtmlImage and add source as BlackArrow Image and set some prop
    HtmlImage imgBarrow = new HtmlImage();
    HtmlTableCell tblCellBarrow = new HtmlTableCell();
    imgBarrow.Src = "/images/Barrow.gif";
    tblCellEmp.Align = "left";

   //attach link button and image to appropriate cells
    tblCellBarrow.Controls.Add(imgBarrow);
    tblCellEmp.Controls.Add(lnkEmp);
   //attach cells to the row...
    tblRowEmp.Cells.Add(tblCellBarrow);
    tblRowEmp.Cells.Add(tblCellEmp);
  //above row is already attached to a table....
  }
}

that is what happening in my Page_Load() event of the page, Please let me know if you dont understand anything...

Thank You,
Steve
This is fine, but I need to know when and where you are going to disable buttons?
when the user clicks on the link button, instead of BlackArrow Image I want to put  Red Arrow Image before the linkbutton (the code I wrote to put black arrow image I want to replace with it similar code to put red arrow image)..

Steve
ASKER CERTIFIED SOLUTION
Avatar of caner_elci
caner_elci

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I am sorry for the late reply, But your code is not working, can you please look into where I am doing wrong... here is what I am doing in my case with your example...

public void Page_Load()
{
  //after opening the database connection and getting the data into the Reader Object
 // this is how my code looks like....
  while(Reader.Read())
  {
   //create a link button for each employee
    LinkButton lnkEmp = new LinkButton();
   // set linkbutton properties
    lnkEmp.ID = Reader["EmpID"].ToString();
    lnkEmp.Text = Reader["EmpName"].ToString() + "<br>";
  //set linkbutton clickevent handler
    lnkEmp.Click += new EventHandler(this.ProcessClick);

   // create a row and cell to attach Image and linkbutton to the page
    HtmlTableRow tblRowEmp = new HtmlTableRow();
    HtmlTableCell tblCellEmp = new HtmlTableCell();
    HtmlTableCell tblCellBarrow = new HtmlTableCell();
   
   //create a HtmlImage and add source as BlackArrow Image and set some prop
    HtmlImage imgBarrow = new HtmlImage();
    HtmlTableCell tblCellBarrow = new HtmlTableCell();
    imgBarrow.Src = "/images/Barrow.gif";
   
// code added..
    imgBarrow.ID = "arrow" + counter // Iam incrementing the counter every call..
    lnkEmp.Attributes.Add("onClick",imgBarrow.ID+".src='/images/Rarrow.gif';");
    lnkEmp.Attributes.Add("href","#");

   //attach link button and image to appropriate cells
    tblCellBarrow.Controls.Add(imgBarrow);
    tblCellEmp.Controls.Add(lnkEmp);
   //attach cells to the row...
    tblRowEmp.Cells.Add(tblCellBarrow);
    tblRowEmp.Cells.Add(tblCellEmp);
  //above row is already attached to a table....
  }
}

in the above code "//code added part "is the one I am changing rest everything I am keeping the same... can you please help me out what's wrong with one Iam doing...
First of all, I have a question.. what are you going to do when users clicks on your lnkEmp? I ask this, because I see that you are adding an event handler to that button, which causes postback (refreshing page and running your server-side code - this.ProcessClick)... So next time the page is loaded, your client-side changes, such as changing image source, will not be seen..
Actually in my case I definitely need to have the post back and the link buttons has to be created dynamically in PageLoad event anyways... I have got the way around in c# without using javascript I have got the solution... but I dont know for some reason your way is not working, I tried to do it in normal way not using my code just sample example, still it was not working... I guess Im doing some thing very wrong...

But still I really appreciate ur help and ofcourse Im accepting ur answer....
I have another Question, I have posted that in ASP.NET section, If you could I would really appreciate your looking at that question.... ..

Thank You,
Steve...
Thank you, I'll check it out..

Caner