Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in my project i need to select the record from grid.from that selected record only id of that particular record should enter in textbox.for that i m using griedview's templetfield property.
and ajax's modelpopup to display grid
on click of ok button i required above mentioned functionality.
here is my code.

XML
//----grid code-----
<cc1:ModalPopupExtender ID="btn_add_student_ModalPopupExtender" runat="server" 
    BackgroundCssClass="modalBackground" CancelControlID="btn_cancel" DynamicServicePath="" 
    Enabled="True" PopupControlID="Panel1" TargetControlID="btn_add_student">
</cc1:ModalPopupExtender>
                
<asp:Panel ID="Panel1" runat="server" BackColor="#C3C3C3" BorderStyle="Outset" BorderWidth="4px">
       <asp:Label ID="Label10" runat="server" Font-Bold="True" Font-Names="Cambria" 
        Font-Size="Large" ForeColor="White" Text="STUDENTS LIST"></asp:Label>
        <asp:GridView ID="GridView1"  runat="server" DataKeyNames="pk_student_id" AutoGenerateColumns="false">
             <Columns>
              <asp:TemplateField>
               <ItemTemplate>
                 <asp:CheckBox ID="ch1" runat="server" />
               </ItemTemplate>
              </asp:TemplateField>
              <asp:TemplateField>
                <HeaderTemplate> STUDENT NAME </HeaderTemplate>
                  <ItemTemplate>
                     <asp:Label ID="lbl_student_name"  runat="server" Text='<%#Eval("student_firstname") %>'></asp:Label>
                  </ItemTemplate>
                </asp:TemplateField> 
             </Columns>
       </asp:GridView>



C#
//-----cs code------
foreach (GridViewRow row1 in GridView1.Rows)
        {
            CheckBox ch= (CheckBox)row1.Cells[0].FindControl("ch1");
            if (ch.Checked == true)
            {
                string sid = GridView1.DataKeys[row1.RowIndex].Value.ToString();
                txt_all_id.Text = sid;
            }

        }
    }
Posted
Updated 23-Feb-10 0:42am
v3

 
Share this answer
 
<br />
string sid = GridView1.DataKeys((row1.RowIndex)("pk_student_id")).ToString();


I hope this will work....
 
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