本文介绍了如何在linkButton上获取Aspx Gridview的行索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我希望在点击链接按钮时得到网格视图的行索引,我的场景是我有aspx网格,它包含aspx文本我希望在点击链接按钮时获得该文本框的值,但我无法做到这一点指导我.. 我的工作是.............. < dx:ASPxGridView ID = gvDisList runat = server KeyFieldName = ID AutoGenerateColumns = False EnableTheming = 真 主题 = Office2003Blue 宽度 = 100% OnPageIndexChanged = gvDisList_PageIndexChanged OnProcessColumnAutoFilter = gvDisList_ProcessColumnAutoFilter > < 列 > < dx:GridViewDataColumn FieldName = ID VisibleIndex = 0 标题 = Shopkeeper / DistributorID 可见 = true / > < dx:GridViewDataColumn FieldName = 名称 标题 = 买方 VisibleIndex = 1 / > < dx:GridViewDataColumn FieldName = 商店名称 标题 = 买方商店名称 VisibleIndex = 2 / > < dx:GridViewDataTextColumn 标题 = 付款 UnboundType = 十进制 > < DataItemTemplate > < dx:ASPxTextBox ID = TextBox1 runat = 服务器 宽度 = 170px > <% - < MaskSettings Mask =& LT; 0..99999&安培; GT;&安培; LT; 00..99&安培; GT; /> - %> < / dx:ASPxTextBox > < asp:RegularExpressionValidator ID = RegularExpressionValidator1 runat = server ValidationExpression = ^(\ d |,)* \。?\d * $ 字体大小 = 小 ControlToValidate = TextBox1 ForeColor = 红色 ErrorMessage = 格式:1234,345,67890或1234,345,67890.0 > < ; / asp:RegularExpressionValidator > < ;% - < asp:TextBox ID =TextBox1runat =server>< / asp:TextBox> - %> < / DataItemTemplate > < / dx:GridViewDataTextColumn > < > < dx:GridViewDataDateColumn 标题 = 插入 > < DataItemTemplate > < asp:LinkButton ID = LinkButton1 runat = server CssClass = btn btn-default 宽度 = 60px 高度 = 35px OnClick = LinkButton1_Click > 插入< / asp:LinkButton > < / DataItemTemplate > < / dx:GridViewDataDateColumn > < /列 > < SettingsPager PageSize = 10 > < / SettingsPager > < 设置 ShowFilterRow = True / > < / dx:ASPxGridView > 链接按钮后面的CS代码是...... DevExpress.Web.ASPxGridView.GridViewDataItemTemplateContainer gvRow =((DevExpress.Web.ASPxGridView .GridViewDataItemTemp lateContainer)((LinkButton的)发送器).NamingContainer); ObjLedger.LedgerDurationID = Convert.ToInt32(ViewState [ LedgerDurationID]); ObjLedger.DistributorID = Convert.ToInt32(lookupDistributor.Value); ObjLedger.ChildTypeID = Convert.ToInt32(LokUpType.Value); ObjLedger.ChildID = Convert.ToInt32(DataBinder.Eval(gvRow.DataItem, ID)的ToString()); ASPxTextBox txtBox1 =(ASPxTextBox)gvDisList.FindRowCellTemplateControl( 1 ,gvDisList.Columns [ 付款] GridViewDataColumn, TextBox1) as ASPxTextBox; // 这里我不是文本框的价值 ObjLedger.Payment = Convert.ToDecimal(txtBox1.Text); ObjLedger.Insert(); lblOutPut.Text = 成功保存; ClientScript.RegisterStartupScript( this .GetType(), HideLabel, < script type = \text / javascript \> ; setTimeout(\document.getElementById(' + lblOutPut.ClientID + ')。 .display ='none'\,3000)< / script>); 解决方案 字体大小 = 小 ControlToValidate = TextBox1 ForeColor = 红色 ErrorMessage = 格式:1234,345,67890或1234,345,67890.0 > < / asp:RegularExpressionValidator > <% - < asp:TextBox ID =TextBox1runat =server>< / asp:TextBox> - %> < / DataItemTemplate > < / dx:GridViewDataTextColumn > < > < dx:GridViewDataDateColumn 标题 = 插入 > < DataItemTemplate > < asp:LinkButton ID = LinkButton1 runat = server CssClass = btn btn-default 宽度 = 60px 高度 = 35px OnClick = LinkButton1_Click > 插入< / asp:LinkButton > < / DataItem模板 > < / dx:GridViewDataDateColumn > < / Columns > < ; SettingsPager PageSize = 10 > < / SettingsPager > < 设置 ShowFilterRow = True / > < / dx:ASPxGridView > 我在链接按钮后面的CS代码是...... DevExpress.Web.ASPxGridView.GridViewDataItemTemplateContainer gvRow =((DevExpress.Web.ASPxGridView.GridViewDataItemTemplateContainer)((LinkButton )发送器).NamingContainer); ObjLedger.LedgerDurationID = Convert.ToInt32(ViewState [ LedgerDurationID]); ObjLedger.DistributorID = Convert.ToInt32(lookupDistributor.Value); ObjLedger.ChildTypeID = Convert.ToInt32(LokUpType.Value); ObjLedger.ChildID = Convert.ToInt32(DataBinder.Eval(gvRow.DataItem, ID)的ToString()); ASPxTextBox txtBox1 =(ASPxTextBox)gvDisList.FindRowCellTemplateControl( 1 ,gvDisList.Columns [ 付款] GridViewDataColumn, TextBox1) as ASPxTextBox; // 这里我不是文本框的价值 ObjLedger.Payment = Convert.ToDecimal(txtBox1.Text); ObjLedger.Insert(); lblOutPut.Text = 成功保存; ClientScript.RegisterStartupScript( this .GetType(), HideLabel, < script type = \text / javascript \> ; setTimeout(\document.getElementById(' + lblOutPut.ClientID + ')。 。显示='none'\ 3000)< /脚本> 中); i want to get row index of grid view when click on link button, my scenario is i have aspx grid, it contains aspx text i want get value of that textbox when click on link button but i am unable to do this kindly guide me.. my working is..............<dx:ASPxGridView ID="gvDisList" runat="server" KeyFieldName="ID" AutoGenerateColumns="False" EnableTheming="True" Theme="Office2003Blue" Width="100%" OnPageIndexChanged="gvDisList_PageIndexChanged" OnProcessColumnAutoFilter="gvDisList_ProcessColumnAutoFilter"> <Columns> <dx:GridViewDataColumn FieldName="ID" VisibleIndex="0" Caption="Shopkeeper/DistributorID" Visible="true" /> <dx:GridViewDataColumn FieldName="Name" Caption="Buyer" VisibleIndex="1" /> <dx:GridViewDataColumn FieldName="ShopName" Caption="Buyer Shop Name" VisibleIndex="2" /> <dx:GridViewDataTextColumn Caption="Payment" UnboundType="Decimal"> <DataItemTemplate> <dx:ASPxTextBox ID="TextBox1" runat="server" Width="170px"> <%-- <MaskSettings Mask="<0..99999>.<00..99> " />--%> </dx:ASPxTextBox> <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ValidationExpression="^(\d|,)*\.?\d*$" Font-Size="Small" ControlToValidate="TextBox1" ForeColor="Red" ErrorMessage="Format: 1234,345,67890 OR 1234,345,67890.0"></asp:RegularExpressionValidator> <%-- <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>--%> </DataItemTemplate> </dx:GridViewDataTextColumn> <> <dx:GridViewDataDateColumn Caption="Insert"> <DataItemTemplate> <asp:LinkButton ID="LinkButton1" runat="server" CssClass="btn btn-default" Width="60px" Height="35px" OnClick="LinkButton1_Click">Insert</asp:LinkButton> </DataItemTemplate> </dx:GridViewDataDateColumn> </Columns> <SettingsPager PageSize="10"> </SettingsPager> <Settings ShowFilterRow="True" /> </dx:ASPxGridView> my CS code behind linkbutton is......DevExpress.Web.ASPxGridView.GridViewDataItemTemplateContainer gvRow = ((DevExpress.Web.ASPxGridView.GridViewDataItemTemplateContainer)((LinkButton)sender).NamingContainer); ObjLedger.LedgerDurationID = Convert.ToInt32(ViewState["LedgerDurationID"]); ObjLedger.DistributorID =Convert.ToInt32( lookupDistributor.Value); ObjLedger.ChildTypeID =Convert.ToInt32( LokUpType.Value); ObjLedger.ChildID = Convert.ToInt32(DataBinder.Eval(gvRow.DataItem, "ID").ToString()); ASPxTextBox txtBox1 = (ASPxTextBox)gvDisList.FindRowCellTemplateControl(1, gvDisList.Columns["Payment"] as GridViewDataColumn, "TextBox1") as ASPxTextBox;// here i am not geeting value of textbox ObjLedger.Payment=Convert.ToDecimal( txtBox1.Text); ObjLedger.Insert(); lblOutPut.Text = "Saved Sucessfully"; ClientScript.RegisterStartupScript(this.GetType(), "HideLabel", "<script type=\"text/javascript\">setTimeout(\"document.getElementById('" + lblOutPut.ClientID + "').style.display='none'\",3000)</script>"); 解决方案 " Font-Size="Small" ControlToValidate="TextBox1" ForeColor="Red" ErrorMessage="Format: 1234,345,67890 OR 1234,345,67890.0"></asp:RegularExpressionValidator> <%-- <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>--%> </DataItemTemplate> </dx:GridViewDataTextColumn> <> <dx:GridViewDataDateColumn Caption="Insert"> <DataItemTemplate> <asp:LinkButton ID="LinkButton1" runat="server" CssClass="btn btn-default" Width="60px" Height="35px" OnClick="LinkButton1_Click">Insert</asp:LinkButton> </DataItemTemplate> </dx:GridViewDataDateColumn> </Columns> <SettingsPager PageSize="10"> </SettingsPager> <Settings ShowFilterRow="True" /> </dx:ASPxGridView> my CS code behind linkbutton is......DevExpress.Web.ASPxGridView.GridViewDataItemTemplateContainer gvRow = ((DevExpress.Web.ASPxGridView.GridViewDataItemTemplateContainer)((LinkButton)sender).NamingContainer); ObjLedger.LedgerDurationID = Convert.ToInt32(ViewState["LedgerDurationID"]); ObjLedger.DistributorID =Convert.ToInt32( lookupDistributor.Value); ObjLedger.ChildTypeID =Convert.ToInt32( LokUpType.Value); ObjLedger.ChildID = Convert.ToInt32(DataBinder.Eval(gvRow.DataItem, "ID").ToString()); ASPxTextBox txtBox1 = (ASPxTextBox)gvDisList.FindRowCellTemplateControl(1, gvDisList.Columns["Payment"] as GridViewDataColumn, "TextBox1") as ASPxTextBox;// here i am not geeting value of textbox ObjLedger.Payment=Convert.ToDecimal( txtBox1.Text); ObjLedger.Insert(); lblOutPut.Text = "Saved Sucessfully"; ClientScript.RegisterStartupScript(this.GetType(), "HideLabel", "<script type=\"text/javascript\">setTimeout(\"document.getElementById('" + lblOutPut.ClientID + "').style.display='none'\",3000)</script>"); 这篇关于如何在linkButton上获取Aspx Gridview的行索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-28 21:06