问题描述
我正在使用aspx网格视图将其与数据表绑定,我有/多行网格绑定我的网格包含文本框我想通过使用每个循环亲切指导得到该文本框的值这个..我的按钮放在网格外面
< html>
< dx:ASPxGridView ID =gvDunamicLedgerrunat =serverAutoGenerateColumns =FalseWidth =100%KeyFieldName =SellerIDSettings-HorizontalScrollBarMode =AutoEnableTheming =TrueTheme =Office2003Blue>
< columns> < dx:gridviewcommandcolumn showclearfilterbutton =Truevisibleindex =0visible =falsexmlns:dx =#unknown>
< dx:gridviewdatacolumn caption =调整unboundtype =Decimalxmlns:dx =#unknown>
< dataitemtemplate>
< dx:ASPxTextBox ID =TAdjustmentrunat =serverWidth =130px> <% - < asp:RegularExpressionValidator ID =RegularExpressionValidator1runat =serverValidationExpression =^(\d |,)* \。?\d * $Font-Size =SmallControlToValidate =TAdjustmentForeColor =RedErrorMessage =Format:1234,345,67890 OR 1234,345,67890.0> <% - < asp:TextBox ID =TextBox1runat =server> - %> - %>
< dx:gridviewdatatextcolumn caption =Encash / Excess Amountunboundtype =Decimalxmlns:dx =#unknown>
< dataitemtemplate>
< dx:ASPxTextBox ID =TEncashAmountrunat =serverWidth =130px>
< dx:gridviewdatatextcolumn caption =Disputed Amountunboundtype =Decimalxmlns:dx =#unknown>
< dataitemtemplate>
< dx:ASPxTextBox ID =TDisputedAmountrunat =serverWidth =130px>
& lt; dx:gridviewdatatextcolumn caption =备注unboundtype =Decimalxmlns:dx =#unknown>
< dataitemtemplate>
< dx:ASPxMemo ID =TRemarksrunat =serverWidth =130px>
<% - < dx:ASPxTextBox ID =TRemarksrunat =serverWidth =170px > - %>
< settings showfilterrow =True>
< Styles AdaptiveDetailButtonWidth =22>< / Styles>
我的代码是
i am using aspx Grid view bind it with data table ,i have /multiple lines of grid when it got bind my grid contains text boxes and i want to get value of that text box by using for each loop kindly guide to get this.. my button placed outside the grid
<html>
<dx:ASPxGridView ID="gvDunamicLedger" runat="server" AutoGenerateColumns="False" Width="100%" KeyFieldName="SellerID" Settings-HorizontalScrollBarMode="Auto" EnableTheming="True" Theme="Office2003Blue">
<columns> <dx:gridviewcommandcolumn showclearfilterbutton="True" visibleindex="0" visible="false" xmlns:dx="#unknown">
<dx:gridviewdatacolumn caption="Adjustment" unboundtype="Decimal" xmlns:dx="#unknown">
<dataitemtemplate>
<dx:ASPxTextBox ID="TAdjustment" runat="server" Width="130px"> <%--<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ValidationExpression="^(\d|,)*\.?\d*$" Font-Size="Small" ControlToValidate="TAdjustment" ForeColor="Red" ErrorMessage="Format: 1234,345,67890 OR 1234,345,67890.0"> <%-- <asp:TextBox ID="TextBox1" runat="server">--%>--%>
<dx:gridviewdatatextcolumn caption="Encash/Excess Amount" unboundtype="Decimal" xmlns:dx="#unknown">
<dataitemtemplate>
<dx:ASPxTextBox ID="TEncashAmount" runat="server" Width="130px">
<dx:gridviewdatatextcolumn caption="Disputed Amount" unboundtype="Decimal" xmlns:dx="#unknown">
<dataitemtemplate>
<dx:ASPxTextBox ID="TDisputedAmount" runat="server" Width="130px" >
<dx:gridviewdatatextcolumn caption="Remarks" unboundtype="Decimal" xmlns:dx="#unknown">
<dataitemtemplate>
<dx:ASPxMemo ID="TRemarks" runat="server" Width="130px">
<%--<dx:ASPxTextBox ID="TRemarks" runat="server" Width="170px">--%>
<settings showfilterrow="True">
<Styles AdaptiveDetailButtonWidth="22"></Styles>
my code is
protected void Button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < gvDunamicLedger.VisibleRowCount; i++)
{
ASPxTextBox tb = gvDunamicLedger.FindRowCellTemplateControl(i, gvDunamicLedger.Columns["Adjustment"] as GridViewDataColumn, "TAdjustment") as ASPxTextBox;
string payment = tb.Text;
ObjInvoices.SellerID = Convert.ToInt32(gvDunamicLedger.GetRowValues(i, "SellerID"));
ObjInvoices.SellerTypeID = Convert.ToInt32(gvDunamicLedger.GetRowValues(i, "SellerTypeID"));
ObjInvoices.BuyerID = Convert.ToInt32(gvDunamicLedger.GetRowValues(i, "BuyerID"));
ObjInvoices.BuyerTypeID = Convert.ToInt32(gvDunamicLedger.GetRowValues(i, "BuyerTypeID"));
ObjInvoices.BusinessAmount =Convert.ToDecimal(gvDunamicLedger.GetRowValues(i, "Payment"));
ObjInvoices.SchemePaymentAmount = Convert.ToDecimal(gvDunamicLedger.GetRowValues(i, "SchemeAmount"));
ASPxTextBox Adjustment = (ASPxTextBox)gvDunamicLedger.FindRowCellTemplateControl(i, gvDunamicLedger.Columns["Adjustment"] as GridViewDataColumn, "TAdjustment") as ASPxTextBox;
ASPxTextBox EncashAmount = (ASPxTextBox)gvDunamicLedger.FindRowCellTemplateControl(i, gvDunamicLedger.Columns["Encash/Excess Amount"] as GridViewDataColumn, "TEncashAmount") as ASPxTextBox;
ASPxTextBox DisputedAmount = (ASPxTextBox)gvDunamicLedger.FindRowCellTemplateControl(i, gvDunamicLedger.Columns["Disputed Amount"] as GridViewDataColumn, "TDisputedAmount") as ASPxTextBox;
ASPxMemo Remarks = (ASPxMemo)gvDunamicLedger.FindRowCellTemplateControl(i, gvDunamicLedger.Columns["Remarks"] as GridViewDataColumn, "TRemarks") as ASPxMemo;
String Adj = Adjustment.Text;
String Encash = EncashAmount.Text;
String Disputed =DisputedAmount.Text;
String Remrk = (Remarks.Text).ToString();
ObjInvoices.Adjustment =Convert.ToDecimal( Adj);
ObjInvoices.EncashExcessAmount =Convert.ToDecimal( Encash);
ObjInvoices.DisputedAmount = Convert.ToDecimal(Disputed);
ObjInvoices.Remarks = Remrk;
ObjInvoices.Insert();
lblOutPut.Text = "insert";
}
}
推荐答案
protected void Button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < gvDunamicLedger.VisibleRowCount; i++)
{
ASPxTextBox tb = gvDunamicLedger.FindRowCellTemplateControl(i, gvDunamicLedger.Columns["Adjustment"] as GridViewDataColumn, "TAdjustment") as ASPxTextBox;
string payment = tb.Text;
ObjInvoices.SellerID = Convert.ToInt32(gvDunamicLedger.GetRowValues(i, "SellerID"));
ObjInvoices.SellerTypeID = Convert.ToInt32(gvDunamicLedger.GetRowValues(i, "SellerTypeID"));
ObjInvoices.BuyerID = Convert.ToInt32(gvDunamicLedger.GetRowValues(i, "BuyerID"));
ObjInvoices.BuyerTypeID = Convert.ToInt32(gvDunamicLedger.GetRowValues(i, "BuyerTypeID"));
ObjInvoices.BusinessAmount =Convert.ToDecimal(gvDunamicLedger.GetRowValues(i, "Payment"));
ObjInvoices.SchemePaymentAmount = Convert.ToDecimal(gvDunamicLedger.GetRowValues(i, "SchemeAmount"));
ASPxTextBox Adjustment = (ASPxTextBox)gvDunamicLedger.FindRowCellTemplateControl(i, gvDunamicLedger.Columns["Adjustment"] as GridViewDataColumn, "TAdjustment") as ASPxTextBox;
ASPxTextBox EncashAmount = (ASPxTextBox)gvDunamicLedger.FindRowCellTemplateControl(i, gvDunamicLedger.Columns["Encash/Excess Amount"] as GridViewDataColumn, "TEncashAmount") as ASPxTextBox;
ASPxTextBox DisputedAmount = (ASPxTextBox)gvDunamicLedger.FindRowCellTemplateControl(i, gvDunamicLedger.Columns["Disputed Amount"] as GridViewDataColumn, "TDisputedAmount") as ASPxTextBox;
ASPxMemo Remarks = (ASPxMemo)gvDunamicLedger.FindRowCellTemplateControl(i, gvDunamicLedger.Columns["Remarks"] as GridViewDataColumn, "TRemarks") as ASPxMemo;
String Adj = Adjustment.Text;
String Encash = EncashAmount.Text;
String Disputed =DisputedAmount.Text;
String Remrk = (Remarks.Text).ToString();
ObjInvoices.Adjustment =Convert.ToDecimal( Adj);
ObjInvoices.EncashExcessAmount =Convert.ToDecimal( Encash);
ObjInvoices.DisputedAmount = Convert.ToDecimal(Disputed);
ObjInvoices.Remarks = Remrk;
ObjInvoices.Insert();
lblOutPut.Text = "insert";
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
TextBox myTextBox = (TextBox)(e.Row.Cells[1].FindControl("TextBoxName"));
//Access yourTextbox here.
string myString = TextBoxName.Text;
}
}
这篇关于如何从aspx gridview获取文本框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!