如何将选定的gridview记录添加到文本框 [英] how to add selected record of gridview to textbox

查看:97
本文介绍了如何将选定的gridview记录添加到文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我需要从网格中选择记录.从选定的记录中,只应在文本框中输入该特定记录的ID.为此,我使用griedview的Templetfield属性.
和ajax的modelpopup显示网格
单击确定按钮时,我需要上述功能.
这是我的代码.

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.

//----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>







//-----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;
            }

        }
    }

推荐答案

请参阅链接并查看示例.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.selectedrow.aspx [
Refer to the link and see the example.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.selectedrow.aspx[^]


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



我希望这可以....



I hope this will work....


这篇关于如何将选定的gridview记录添加到文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆