How to check gridview last row textbox value in asp.net?
Please tell me how to get gridview last row textboxe's value in Button Click Event.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Arunava BhattacharjeeRank #635 · 3.8K reputationPosted Sep 15, 2014, 7:51 PM EDT
Sunny Shaikh50 reputationPosted Sep 15, 2014, 11:30 PM EDT
<asp:GridView ID="idgvDetail" runat="server" Width="100%" ShowFooter="true" AutoGenerateColumns="false"
CssClass="Gridview" HeaderStyle-BackColor="#788801" HeaderStyle-ForeColor="White">
<AlternatingRowStyle BackColor="#EEEEEE" />
<Columns>
<asp:TemplateField HeaderText="Sale ID">
<ItemTemplate>
<asp:Label ID="SaleID" runat="server" Text='<%# Eval("SaleID") %>'>asp:Label>
ItemTemplate>
asp:TemplateField>
<asp:BoundField DataField="SaleSrNo" HeaderText="S.No." ItemStyle-Width="10px" />
<asp:TemplateField HeaderText="Shoes ID">
<ItemTemplate>
<asp:Label ID="ShoesID" runat="server" Text='<%# Eval("ShoesID") %>'>asp:Label>
ItemTemplate>
asp:TemplateField>
<asp:TemplateField HeaderText="Shoes Code">
<ItemTemplate>
<asp:TextBox ID="ShoesCode" runat="server" Text='<%# Bind("ShoesCode") %>' OnTextChanged="ShoesCode_TextChanged"
AutoPostBack="true" Width="70px">asp:TextBox>
ItemTemplate>
asp:TemplateField>
<asp:TemplateField HeaderText="Shoes Name">
<ItemTemplate>
<asp:Label ID="ShoesName" runat="server" Text='<%# Eval("ShoesName") %>'>asp:Label>
ItemTemplate>
asp:TemplateField>
<asp:TemplateField HeaderText=" Shoes Rate">
<ItemTemplate>
<asp:TextBox ID="SaleRate" runat="server" Text='<%# Bind("SaleRate") %>' Width="70px">asp:TextBox>
ItemTemplate>
asp:TemplateField>
<asp:TemplateField HeaderText="Quantity">
<ItemTemplate>
<asp:TextBox ID="SaleQty" runat="server" Text='<%# Bind("SaleQty") %>' Width="70px">asp:TextBox>
ItemTemplate>
asp:TemplateField>
<asp:TemplateField HeaderText="Amount">
<ItemTemplate>
<asp:Label ID="SaleAmnt" runat="server" Text='<%# Eval("SaleAmnt") %>' Width="70px">asp:Label>
ItemTemplate>
<FooterStyle HorizontalAlign="Right" />
<FooterTemplate>
<asp:Button ID="btnAddRow" runat="server" CssClass="inputsubmit" Text="Add Row" OnClick="btnAddRow_Click" />
FooterTemplate>
asp:TemplateField>
Columns>
asp:GridView>
---------------------------------------------------------------------
protected void btnAddRow_Click(object sender, EventArgs e)
{
//Here I want to check last row data. If the data fill in these textbox (ShoesCode, SaleRate, SaleQty) then AddRowToGrid function work.
AddRowToGrid();
}
Ajay Verma4 reputationPosted Sep 16, 2014, 12:42 AM EDT
Y hv 2 use this code, it could be help you.
the code be become on button event
.
Arunava BhattacharjeeRank #635 · 3.8K reputationPosted Sep 16, 2014, 2:00 AM EDT
string value=null;
foreach (GridViewRow row in YourGridViewName.Rows)
{
var textbox = row.FindControl("YourTextBoxName") as TextBox;
value = textbox.Text;
}
if(!String.IsNotNullOrEmpty(value))
//call your method.
If it satisfies you then please mark the answer as accepted.