Click here to Skip to main content
15,916,379 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
i need to get the value of the column which is a template field on check box and button click events of a gridview

am having gridview control, having 3 columns for row
1st column having checkboxes
2nd column string values
and 3rd column buttons
When i check the checkbox i want the value of 2nd column to be displayed on button click
can anyone suggest me the solution

thanks inadvance
Posted
Updated 17-Aug-11 0:24am
v4
Comments
Herman<T>.Instance 17-Aug-11 5:05am    
please refrase your question. I cannot understand your problem
pradeep manne 17-Aug-11 5:09am    
am having 3 columns in my grid ,i need to display a column value of the row
on checkbox and button click which are also the columns of gridview

By using this code you have the gridview row in which the button was clicked.
in the onclick event of your button:

Button btn = (Button)sender;
GridViewRow row = (GridViewRow)btn.NamingContainer;


By using this code you have the gridview row in which the checkbox was clicked.
in the onselectedChanged event of your checkbox:
CheckBox chkbx = (CheckBox)sender;
GridViewRow row = (GridViewRow)chkbx.NamingContainer;
if (chkbx.Checked)
{
 /// your code here to do with the textbox what ever you need to do.

}


I cannot give a more precize answer cause I do not know whether the checkbox or the button shows the value in column 2
 
Share this answer
 
  <asp:GridView ID="grdFmlHist" runat="server" AllowPaging="True" Enabled ="False"
    AutoGenerateColumns="False" DataKeyNames="Relationship" Height="40px" WIDTH="450px"
    PageSize="8" ShowFooter="True"  onrowdatabound="grdFmlHist_RowDataBound" >
    <PagerSettings Mode="NumericFirstLast" />
    <RowStyle BackColor="WhiteSmoke" BorderColor="CornflowerBlue" ForeColor="Black"
        Height="30px" />
    <Columns>
    <asp:TemplateField HeaderText="S.No">
          <ItemTemplate>
              <asp:CheckBox ID="chkSelect" runat="server" />
        </ItemTemplate>
         </asp:TemplateField>
         <asp:TemplateField HeaderText="S.No">
          <ItemTemplate>
            <%# ((GridViewRow)Container).RowIndex + 1%>
        </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="Relationship" HeaderText="Relationship" />
        <asp:BoundField DataField="Disease" HeaderText="Disease" />
        <asp:BoundField DataField="Dates" HeaderText="Dates" />
        <asp:TemplateField>
        <ItemTemplate>
            <asp:Button ID="btnDisplay" runat="server"  /></ItemTemplate>
        </asp:TemplateField>
      </Columns>
    <FooterStyle BackColor="Silver" Height="25px" />
    <PagerStyle BackColor="DarkGray" />
    <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
</asp:GridView>


]]>
protected void chkSelect_CheckedChanged(object sender, EventArgs e)
       {
           if (chkSelect.Checked == true)
           {
               btnDisplay.text=chkSelect.Text;
           }
           else
           {
              btnDisplay.text="";
           }
       }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900