How to select a gridview row

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • btreddy
    New Member
    • Oct 2008
    • 83

    How to select a gridview row

    Hii experts,
    I've been trying for this but i didn succeeded.The problem is
    I've a datagird which is having 2 cols displaying name and emial id .wht i want is when i select a paricular row from the gridview i want to capture the emial id value of tht paricular row.
    I've added this code in the even onrowdatatbound .
    Code:
    protected void GridViewParticipants_OnRowDataBound(object sender, GridViewRowEventArgs e) 
    
    / 
    .
    . 
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    e.Row.ID = e.Row.Cells[0].Text.ToString();
    e.Row.Attributes.Add("onclick", "javascript:Ongridrowselected('"+e.Row+ "','" + e.Row.Cells[0].Text + "')");
    e.Row.Attributes.Add("onmousehover", "javascript:Ongridrowmousehover('" + e.Row + "')"); 
    }
    The below are th two javascript functions.
    var lastselectedrow; 
    var originalcolor;
     
    function Ongridrowselected(row,emailid) 
    {
     
    var hidden=document.getElementById('hdnemailid') 
    hidden.value=emailid;
     
    if(lastselectedrow !=row) 
    {
     
    if(lastselectedrow != null) 
    {
     
    lastselectedrow.style.backgroundColor=originalcolo  r;
     
    lastselectedrow.stylr.color='Black';lastselectedro  w.style.fontWeight='normal'; 
    }
     
    originalcolor=row.style.backgroundColor;
     
    row.style.backgroundColor='BLACK'; 
    row.style.color='White';
     
    row.style.fontWeight='normal'; 
    lastselectedrow=row;
     
    }
     
    }
     
    function Ongridrowmousehover(row) 
    {
     
    row.style.cursor='hand'; 
     
     }
    Dont know why the rows are not getting selected when i place the mouse on the row.
    Plz tell me ehr is thr mistake.
    Thank you..
    **sorry for the bad english.
    Regards,
    BTR.
    [/SIZE]
    Last edited by acoder; Jan 16 '09, 08:39 AM. Reason: Added [code] tags
  • btreddy
    New Member
    • Oct 2008
    • 83

    #2
    Hii experts,

    I've been trying for this but i didn succeeded.The problem is

    I've a datagird which is having 2 cols displaying name and emial id .wht i want is when i select a periculer row from the gridview i want to capture the emial id value of tht perticuler col.

    I've added this code in the even onrowdatatbound .
    Code:
    protected void GridViewParticipants_OnRowDataBound(object sender, GridViewRowEventArgs e)
     
    / 
     
    .
     
    .
     
     
     
    if (e.Row.RowType == DataControlRowType.DataRow) 
    {
     
    e.Row.ID = e.Row.Cells[0].Text.ToString();
     
    e.Row.Attributes.Add("onclick", "javascript:Ongridrowselected('" +e.Row+ "','" + e.Row.Cells[0].Text + "')");e.Row.Attributes.Add("onmousehover", "javascript:Ongridrowmousehover('" + e.Row + "')"); 
    }
     
    The below are th two javascript functions.
     
    var lastselectedrow; 
    var originalcolor;
     
    function Ongridrowselected(row,emailid) 
    {
     
    var hidden=document.getElementById('hdnemailid') 
    hidden.value=emailid;
     
    if(lastselectedrow !=row) 
    {
     
    if(lastselectedrow != null) 
    {
     
    lastselectedrow.style.backgroundColor=originalcolor;
     
    lastselectedrow.stylr.color='Black';lastselectedrow.style.fontWeight='normal'; 
    }
     
    originalcolor=row.style.backgroundColor;
     
    row.style.backgroundColor='BLACK'; 
    row.style.color='White';
     
    row.style.fontWeight='normal'; 
    lastselectedrow=row;
     
    }
     
    }
     
    function Ongridrowmousehover(row) 
    {
     
    row.style.cursor='hand'; 
     
     
    }
    Dont know why the rows are not getting selected when i place the mouse on the row.

    Plz tell me ehr is thr mistake.

    Thank you..

    **sorry for the bad english.

    Regards,

    BTR.
    Last edited by acoder; Jan 16 '09, 08:40 AM. Reason: Added [code] tags

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      Post the client-side version of your code (in code tags please).

      A few notes:
      1. check typos: I see a stylr instead of style.
      2. check errors in your error console: it should highlight any errors
      3. It's onmouseover, not onmousehover
      4.'hand' is not a valid cursor value. It should be 'pointer'.

      Comment

      • btreddy
        New Member
        • Oct 2008
        • 83

        #4
        Hiii acoder ,Thanks for your reply.

        I correctd the typo errors....but its not working .

        i put a breakpoint ,its showing tht the value os e.Row.Cells[0].Text as "null".


        client-side version code means the source code you are asking ,right.(IE-->View-->Source) .

        Its a very huge file...can not post it here.

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          You only need to post the relevant parts - not the whole page. Alternatively, post a link to a page that we can look at.

          Comment

          Working...