Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Get Textbox Value Placed in Asp.net Gridview using C#

Nov 4, 2014
Introduction

Here I will explain how to find or get text box value placed in
gridview in asp.net or how to find controls (textbox, dropdownlist, checkbox,radio button etc..) in inside of asp.net gridview using c#.


Generally if we want to find or get value from controls which is inside of gridview we will write the code like as shown below


DropDownList ddl = (DropDownList)gvUserInfo.FindControl("yourControlName");
string ddlValue = ddl.SelectedItem.Value;
TextBox txtUserInfo = (TextBox) gvUserInfo.FindControl("yourControlName");
string strValue = txtUserInfo.Text;

In case if we want to find controls inside gridview in rowdatabound condition we will write code like this


protected void gvUserInfo_RowDataBound(object sender, GridViewRowEventArgs e)
{
DropDownList ddl = (DropDownList)gvUserInfo.FindControl("yourControlName");
string ddlValue = ddl.SelectedItem.Value;
TextBox txtUserInfo = (TextBox) gvUserInfo.FindControl("yourControlName");
string strValue = txtUserInfo.Text;
}

Suppose if we have controls in each row of gridview then we need find each row of controls for that we need to write a code like this


protected void gvUserInfo_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddl = (DropDownList)e.Row.FindControl("ddlCity");
int CountryId = Convert.ToInt32(ddl.SelectedItem);
}
}

If you want to see it in example check below articles to bind controls in gridview and get control values


If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

0 comments :

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.