如何从Datagrid视图中返回值? [英] How Do I Retrive A Value From Datagrid View?

查看:105
本文介绍了如何从Datagrid视图中返回值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hai朋友,

我用datagridview设计一个表单。

如果我点击datagridview中的一个单元格,它应显示或所选行的第一个单元格值

谢谢,

问候,

Sissy ram

Hai friends,
I am desiging a form with datagridview.
If i click a cell in the datagridview it should display or the 1st cell value of the selected row
Thank you,
regards,
Sissy ram

推荐答案

使用< a href =http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.selectionchanged%28v=vs.110%29.aspx> DataGridView.SelectionChanged [< a href =http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.selectionchanged%28v=vs.110%29.aspxtarget =_ blanktitle =新窗口> ^ ]事件。点击链接,使用提供的代码并根据需要进行更改。
Use DataGridView.SelectionChanged[^] event. Follow the link, use the code there provided and change it depending on your needs.


你必须使用Rowcommand Event



< asp:gridview id =Gemployeemasterrunat =serverbackcolor =Whitexmlns:asp =#unknown>

BorderColor =WhiteBorderStyle =RidgeBorderWidth = 2pxCellPadding =3

CellSpacing =1GridLines =Noneonrowcommand =Gemployeemaster_RowCommand

AllowPaging =TrueWidth =308px

onpageindexchanged =Gemployeemaster_PageIndexChanged

onpageindexchanging =Gemployeemaster_PageIndexChanging>

< footerstyle backcolor =#C6C3C6forecolor =Black> ;

< rowstyle backcolor =#DEDFDEforecolor =Black>

< columns> < asp:buttonfield commandname =编辑headertext =编辑text =编辑>

< pagerstyle backcolor =#C6C3C6forecolor =Blackhorizo​​ntalalign =Right> ;

< SelectedRowStyle BackColor =#9471DEFont-Bold =TrueForeColor =White/>

< HeaderStyle BackColor =#4A3C8C Font-Bold =TrueForeColor =#E7E7FF/>





< asp:textbox id =Tempcode runat =serverxmlns:asp =#unknown>

代码背后





protected void Gemployeemaster_RowCommand(object sender,GridViewCommandEventArgs e)

{

if(e.CommandName ==Edit)

{

Int16 num = Convert.ToInt16(e.CommandArgument);

//您希望在文本框或其他地方设置的数据单元数据位置

Tempcode.Text = Gemployeemaster.Rows [num] .Cells [1] .Text;







}

}
You have to use Rowcommand Event

<asp:gridview id="Gemployeemaster" runat="server" backcolor="White" xmlns:asp="#unknown">
BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3"
CellSpacing="1" GridLines="None" onrowcommand="Gemployeemaster_RowCommand"
AllowPaging="True" Width="308px"
onpageindexchanged="Gemployeemaster_PageIndexChanged"
onpageindexchanging="Gemployeemaster_PageIndexChanging">
<footerstyle backcolor="#C6C3C6" forecolor="Black">
<rowstyle backcolor="#DEDFDE" forecolor="Black">
<columns> <asp:buttonfield commandname="Edit" headertext="Edit" text="Edit">
<pagerstyle backcolor="#C6C3C6" forecolor="Black" horizontalalign="Right">
<SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />


<asp:textbox id="Tempcode" runat="server" xmlns:asp="#unknown">
And code behind


protected void Gemployeemaster_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName =="Edit")
{
Int16 num = Convert.ToInt16(e.CommandArgument);
// which data cell data you want to get in textbox or elsewhere set there position
Tempcode.Text=Gemployeemaster.Rows[num].Cells[1].Text;



}
}


这篇关于如何从Datagrid视图中返回值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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