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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Arunava BhattacharjeePosted Sep 16, 2014, 6:00 AM
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.
Ajay VermaPosted Sep 16, 2014, 4:42 AM
Y hv 2 use this code, it could be help you.
the code be become on button event
.
Sunny ShaikhPosted Sep 16, 2014, 3:30 AM
<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();
}
Arunava BhattacharjeePosted Sep 15, 2014, 11:51 PM