Rating Cotrol inside gridview

Rate It (1)

Last post 05-17-2008 3:23 AM by nikitaprajapati. 3 replies.

Sort Posts:

  • Rating Cotrol inside gridview

    04-29-2008, 8:23 AM

    Hi.

    I am having rating control inside the gridview which will rate my post . and then i want to update the perticular post based on given rating.

    What i have did is like

    protected void Rating1_Changed(object sender, AjaxControlToolkit.RatingEventArgs e)

    {

    AjaxControlToolkit.Rating myRating = (AjaxControlToolkit.Rating)sender;

    System.Text.RegularExpressions.Regex rexLineNo = new System.Text.RegularExpressions.Regex("ctl\\d+");

    this.updateRating(this.ProductId(rexLineNo.Match(myRating.UniqueID).ToString()), e.Value);

     

    }

    This work fine when i m not using master page.

    but when i am using master page it by default gives me first record number and it update first record.

    Please advice me ASAP.

     M stuck in this issue like a hell.

     

     

    private string ProductId(string LineNo)

    {

     

    foreach (GridViewRow r in this.GridView2.Rows)

    {

    Label lblProductId = new Label();

    lblProductId = (Label)r.FindControl("lblTransactionId");

    // if label's uniqueID (the one created by ASP and rendered as a long thing with prefixes and line numbers)

    // contains the same number (and prefix) as the one passed in

    if (lblProductId.UniqueID.Contains(LineNo))

    {

    // return label's text, which is your product ID:

    return lblProductId.Text;

    }

    }

    Nikita Prajapati
  • Re: Rating Cotrol inside gridview

    04-30-2008, 2:16 AM

    hi.. noone having solution for this..please reply me i need this...

    Nikita Prajapati
  • Re: Rating Cotrol inside gridview

    05-05-2008, 10:33 AM
    • Loading...
    • varshacon
    • Joined on 05-05-2008, 11:00 AM
    • Posts 21

    I too need it urgently. Any small help will be highly highly appreciated.

  • Re: Rating Cotrol inside gridview

    05-17-2008, 3:23 AM
    Answer

    hi i have found the solution and i would like to share and which is as follow.

    on the rating change event put this code

    AjaxControlToolkit.Rating myRating = (AjaxControlToolkit.Rating)sender;

    GridViewRow GridItem = (GridViewRow)myRating.Parent.Parent.Parent.Parent.Parent; // (this will depends on ur grid stucture m having 2 tables inside itemtemplate)

    this.updateRating(((Label)GridItem.FindControl("lblTransactionId")).Text, e.Value);

     

    myRating.Enabled =
    false;

    myRating.ReadOnly = true;

     

     

    private void updateRating(String Id, String Rating)

    {

    SqlCommand cmdInsertPostReply = new SqlCommand();

    cmdInsertPostReply.CommandText = "SPName";

    cmdInsertPostReply.CommandType = CommandType.StoredProcedure;

    cmdInsertPostReply.Connection = objGeneral.con;

    cmdInsertPostReply.Parameters.AddWithValue(
    "@Id", Convert.ToInt64(Id.ToString()));cmdInsertPostReply.Parameters.AddWithValue("@rate", Convert.ToInt16(Rating.ToString()));

    objGeneral.connect();

    cmdInsertPostReply.ExecuteNonQuery();

    objGeneral.closeconnect();

    }

    Nikita Prajapati
Page 1 of 1 (4 items)