如何获取数据gridview行中的第一个单元格 [英] How to get the first cell in data gridview row

查看:74
本文介绍了如何获取数据gridview行中的第一个单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 -



我有一个数据绑定网格,当点击一行时,我需要从单击的行的第一个单元格中取出值。我不确定如何在数据网格上实现这一点。这是数据网格的代码。理想情况下我想要的是当单击行获取第一个单元格的值时,所以在后面的代码中我可以将该值作为商店过程中的参数传递。



Hi -

I have a data bound grid and when a row is clicked I need the value out of the first cell of the row that was clicked. I'm not exactly sure how to achieve this on a data grid. Here is the code for the data grid. Ideally what I want is when the row is clicked get the value of the first cell so in the code behind I can pass that value as a parameter in a store procedure.

<asp:datagrid id=dgListaDistributori runat="server" CssClass="tblDGStandard" Width="100%" HeaderStyle-VerticalAlign="Middle" HeaderStyle-Height="20" ShowHeader="True" AutoGenerateColumns="False" OnPageIndexChanged="PageGrid2" AllowPaging="True" CellSpacing="1" CellPadding="0" BorderWidth="0px">  <AlternatingItemStyle CssClass="tblDGStandardAlt"></AlternatingItemStyle>
	 <Columns>
		 <asp:BoundColumn DataField="DISV_CODDIS" HeaderText="Cod.Distr.">
			<ItemStyle Height="20"></ItemStyle>
							                <HeaderStyle CssClass="tblDGStandardHeader" Width="60"></HeaderStyle>
						                </asp:BoundColumn>
						                
						                <asp:BoundColumn DataField="DISV_NAZIONE" HeaderText="Naz.">
							                <ItemStyle Height="20"></ItemStyle>
							                <HeaderStyle CssClass="tblDGStandardHeader" Width="20"></HeaderStyle>
						                </asp:BoundColumn>
						                				
						                	
						                <asp:TemplateColumn HeaderStyle-CssClass="tblDGStandardHeader" HeaderStyle-Width="20">
                                            <ItemTemplate>
                                                <asp:ImageButton id="btnCancelDis" Runat="server" ImageUrl="img\delete.gif" CommandName="CancellaDis"></asp:ImageButton>
                                                <ajaxToolkit:ConfirmButtonExtender ID="ajaxCBE1"  runat="server" TargetControlID="btnCancelDis" />                                                               
                                            </ItemTemplate>
                                        </asp:TemplateColumn>
                                        <asp:TemplateColumn HeaderStyle-CssClass="tblDGStandardHeader" HeaderStyle-Width="20">
                                            <ItemTemplate>
                                                <asp:ImageButton id="switchAccount" Runat="server" ImageUrl="img\refresh.png"  CommandName="logOut"></asp:ImageButton>                                                
                                            </ItemTemplate>
                                        </asp:TemplateColumn>
</Columns>
					               
</asp:datagrid>

推荐答案

根据上面列出的内容,您需要创建OnSelectedIndexChanged事件的事件处理程序 - 见下文;



Based on what is listed above, you need to create an event handler for the OnSelectedIndexChanged event - see below;

<asp:datagrid id="dgListaDistributori" runat="server" cssclass="tblDGStandard" width="100%" headerstyle-verticalalign="Middle" headerstyle-height="20" showheader="True" autogeneratecolumns="False" onpageindexchanged="PageGrid2" allowpaging="True" cellspacing="1" cellpadding="0" borderwidth="0px" xmlns:asp="#unknown"> OnSelectedIndexChanged="gListaDistributori_SelectedIndexChanged"></asp:datagrid>





在您的代码中,您可以按如下方式访问单元格值;



In your code behind you can then access the cell value as follows;

Dim strMyValue as String
strMyValue = dgListaDistributori.SelectedItem.Cells(1).Text


这篇关于如何获取数据gridview行中的第一个单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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