Skip to content

Gridview with checkbox

samanta

Asked Jan 23, 2014, 3:00 AM EST5 answers
Share
LinkedInX
hii,
i have gridview which displays cityname and Price.
i have one checkbox which is dynamically created based on  number of city.
functionality:
when cityname checkbox checked  respective price must be displayed based on citycode. How to achieve this please assist.

4 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    C#
    protected void chkCity_OnCheckedChanged(object sender, EventArgs e)
            {
    
    
            GridViewRow row = (GridViewRow)(((CheckBox)sender).NamingContainer);
            HiddenField hdCityCodeValue = (HiddenField)row.Cells[0].FindControl("hdCityCode");
            HiddenField hdStandardCost = (HiddenField)row.Cells[0].FindControl("hdCostStandard");
            Label objLabelPrice = (Label)row.FindControl("lblPrice");
    
    
            int cityCode = Convert.ToInt32(hdCityCodeValue.Value);
            string standardPrice = hdStandardCost.Value;
    if (((CheckBox)sender).Checked == true)
                        {
                          objLabelPrice.Visible = true;
                            objLblTestCityCode.Text = cityCode.ToString();
                            objLabelPrice.Text = "Rs. " + standardPrice;
    
    
                           if (cityCode == -1)
                          {
                               (grdView.Rows[i].FindControl("chkCity") as CheckBox).Checked = false;
                               (grdView.Rows[i].FindControl("chkCity") as CheckBox).Enabled = false;
                               objLblTestCityCode.Text = cityCode.ToString();
                               objLabelPrice.Text = "Rs. " + standardPrice;
                              ((CheckBox)sender).Enabled = true;
                               ((CheckBox)sender).Checked = true;
                               objLabelPrice.Visible = true;
                           }
    
    
                                checkcount = checkCount();
                                if (checkcount == count)
                                {
                                    for (int j = 0; j < grdView.Rows.Count; j++)
                                   {
                                       if ((grdView.Rows[j].FindControl("chkCity") as CheckBox).Checked == true)
                                       {
                                            (grdView.Rows[j].FindControl("chkCity") as CheckBox).Enabled = false;
                                           (grdView.Rows[j].FindControl("chkCity") as CheckBox).Checked = false;
                                           objLabelPrice.Text = "";
                                       }
                                       else
                                       {
                                          (grdView.Rows[j].FindControl("chkCity") as CheckBox).Checked = true
                                        }
    
    
                                   }
                                }
    
    
    
                       }
                        else
                       {
                            objLabelPrice.Visible = false;
                            (grdView.Rows[i].FindControl("chkCity") as CheckBox).Enabled = true;
                        }
    
    
    }
    0
  • 0
    when i click on All india(citycode = -1) all other checkbox must be disabled and if  when all city checked All  india must be disabled.
    0
  • Biswa Pujarini Mohapatra
    0
    can you paste your aspx page as well also can you explain what is the use of checkcount() class
    0
  • 0
    AutoGenerateColumns="False" HeaderStyle-HorizontalAlign="Left" 
                                BorderStyle="None"  
                                RowStyle-HorizontalAlign="Left" GridLines="None" >                      
                         
             
                 
               
                   
       




                   





     <%# DisplayProductCity(((System.Data.DataRowView)Container.DataItem).Row)%>
                   
                   
                   

       
                 
                     
                     
                     
             
             
               <%--   --%>
                       <%----%>





                   <%# DisplayProductPrice(((System.Data.DataRowView)Container.DataItem).Row)%>
                     


     
    0
  • 1 short reply