Active Server Pages

Moderators: None (Apply to moderate this forum)
Number of threads: 1763
Number of posts: 4498

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Get Cell value + GridView + ASP Posted by sonu_1984 on 1 Apr 2009 at 12:41 PM
I bound gridview with databse..property Checkbox -true .
I have three columns roll,name ,roll.

I want to get the cell value of second column whose corresponding checkboxes are checked...

on Button1_Click, in varable bchecked,checkboxes status are coming..I want to get the cell value..Plz help me out..

SOURCE TAB
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">   
                  
   <Columns>      
                 
<asp:TemplateField >  

    <ItemTemplate >     
              
     <asp:CheckBox ID ="chk" runat ="server"  />       
  
               </ItemTemplate>    
            
        </asp:TemplateField>     
        
   <asp:BoundField HeaderText="Roll" DataField ="roll" />            
            
   <asp:BoundField HeaderText="Name"  DataField ="name"/>                       

<asp:BoundField HeaderText="Marks" DataField ="marks"/>             

           </Columns>    
              
  </asp:GridView>

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"> 

<Columns> 


protected void Page_Load(object sender, EventArgs e)
    {
      if (!IsPostBack       
         {

            query = "Select * from Information";
            conn.Open();
            cmd = new SqlCommand(query, conn);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            GridView1.DataSource = ds;
            GridView1.DataBind();
            conn.Close();
       }
    }




    protected void Button1_Click(object sender, EventArgs e)
    {
        string sName;
        bool bchecked;

        for (int i = 0; i < this.GridView1.Rows.Count; i++)
        {
            bchecked = ((CheckBox)GridView1.Rows[i].FindControl("chk")).Checked;
            if (bchecked == true)
            {
                Label lblName = (Label)GridView1.FindControl("Name") ;
                sName = lblName.ToString ;
               
            }

           
        }
        

    }



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.