请帮我找到解决方案 [英] Please help me find the solution

查看:68
本文介绍了请帮我找到解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

需要有人展示如何从gridview列中获取价值到文本框中.
例如,如果我有带有4列ID,NAME,ADDRESS和EMAIL的"GridViewEmployee".
还有一个模板字段,在模板字段中,一个链接按钮位于ITEMTEMPLATE中.当单击GRIDVIEW中的链接按钮特定值时,将在所有相应的文本框中显示.

我仍在使用C#学习asp.net,我试图做许多选择,但不知何故没有结果.

我的HTML代码是

Hello,

Need someone to show how to get value from gridview column into textbox.
For example if I have "GridViewEmployee" with 4 columns ID, NAME,ADDRESS and EMAIL.
AND ALSO A TEMPLATEFIELD, IN TEMPLATEFIELD ONE LINKBUTTON IS PLACES INSIDE ITEMTEMPLATE. WHEN CLICK ON LINK BUTTON PARTICULAR VALUE FROM GRIDVIEW WILL DISPLAY ON ALL CORRESPONDING TEXTBOXES.

I''m still learning asp.net using C#, and I was trying to do many options, but somehow could not get result.

MY HTML CODE IS

<pre lang="xml"><asp:GridView ID="empGV" runat="server" AutoGenerateColumns="False"

                        CellPadding="4" DataKeyNames="eid" DataMember="employee" ForeColor="#333333"

                        GridLines="None" Width="500px">
                        <RowStyle BackColor="#EFF3FB" />
                        <Columns>
                            <asp:BoundField DataField="eid" HeaderText="Employee Id" />
                            <asp:BoundField DataField="ename" HeaderText="Employee Name" />
                            <asp:BoundField DataField="eaddress" HeaderText="Employee Address" />
                            <asp:TemplateField HeaderText="Select">
                                <ItemTemplate>
                                <asp:LinkButton ID="lbSelect" runat="server">Edit</asp:LinkButton>
                                    <%--<asp:LinkButton ID="lbSelect" runat="server"
                                        CommandName="EDIT">Edit</asp:LinkButton>--%>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                        <EditRowStyle BackColor="#2461BF" />
                        <AlternatingRowStyle BackColor="White" />
                    </asp:GridView>




和代码隐藏代码为:

这是我最近的代码:
textbox1.text = GridViewEmployee.rows [0] .cells(ID);
textbox2.text = GridViewEmployee.rows [0] .cells(NAME);
textbox3.text = GridViewEmployee.rows [0] .cells(ADDRESS);
textbox4.text = GridViewEmployee.rows [0] .cells(EMAIL);
或我也尝试过这个,但都无法正常工作
我将使用"SELECTEDINDEX或"ITEMCOMMAND"或其他任何代码"的代码
这里有一些试验代码;
受保护的void empGV_SelectedIndexChanged(对象发送者,EventArgs e)
{

GridViewRow行= empGV.SelectedRow;
textbox1.Text = row.Cells [1] .Text;
textbox2.Text = row.Cells [2] .Text;


如果没有任何关于使用模板来进行GRIDVIEW操作的代码,则不在内置的REASYMADE EDIT或UPDATE TEMPLATE(COMMANDFIELD)中.

}


预先感谢您对任何人的帮助.




AND CODEBEHIND CODE IS:

This is nearest I was with the code:
textbox1.text = GridViewEmployee.rows[0].cells(ID);
textbox2.text = GridViewEmployee.rows[0].cells(NAME);
textbox3.text = GridViewEmployee.rows[0].cells(ADDRESS);
textbox4.text = GridViewEmployee.rows[0].cells(EMAIL);
or i have also tried this one but both are not working
WHICH CODE I WILL USE "SELECTEDINDEX OR "ITEMCOMMAND" OR ANYTHING ELSE"
SOME TRIAL CODE IS HERE;
protected void empGV_SelectedIndexChanged(object sender, EventArgs e)
{

GridViewRow row = empGV.SelectedRow;
textbox1.Text = row.Cells[1].Text;
textbox2.Text = row.Cells[2].Text;


IF ANY HAVE CODE ABOUT GRIDVIEW MANIPULATION USING TEMPLATEFIELD NOT IN BUILT REASYMADE EDIT OR UPDATE TEMPLATE(COMMANDFIELD).

}


Thank you in advance for help to anyone.

推荐答案

您好,拉吉夫

试试这个

使用ButtonField代替TemplateField

< asp:buttonfield text =编辑" buttontype =链接" commandname =删除" xmlns:asp =#unknown">


受保护的void empGV_RowCommand(对象发送者,GridViewDeleteEventArgs e)
{
///使用//e.RowIndex从网格获取值
}
Hi Rajiv

try this

use ButtonField in place of TemplateField

<asp:buttonfield text="Edit" buttontype="Link" commandname="Delete" xmlns:asp="#unknown">


protected void empGV_RowCommand(object sender, GridViewDeleteEventArgs e)
{
/// Use // e.RowIndex to get value from grid
}


这篇关于请帮我找到解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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