1

I am new to asp.net website developer. In my website I use GridView Control.In the GridView row i place some controls like TextBox,DropDownList.

I can display the values in GridView.

But my requirement is ,Get the values from TextBox and DropdownList Which are existed in GridView.

Please help me to go forward..

thank you, bye..

2

4 Answers 4

1

You need to access them by row. This code project article explains it in detail.

TextBox tb = (TextBox)gridview1.Rows[0].FindControl("idOfTextBox");

It above statement will find control in the first row of grid which has id idOfTextBox and type is textbox.

Sign up to request clarification or add additional context in comments.

Comments

0

You can directly get any value of any control by casting directly, without using an extra textbox or dropdown variable.

Example:

string val = ((TextBox)gridview1.Rows[0].FindControl("TextBox_ID")).Text;

Hope it helps :)

Comments

0
Subscribe the RowDataBound event(this will be fired on each row available in gridview) of gridview and access like stated below,

protected void grdBillingdata_RowDataBound(object sender, GridViewRowEventArgs e)
{
        if (e.Row.RowType == DataControlRowType.DataRow)
        {   
           //these controls are available inside gridview

            HiddenField hdnNagetiveAmt = (HiddenField)e.Row.FindControl("hdnNagetiveAmt");
            DropDownList ddlFeeType = (DropDownList)e.Row.FindControl("ddlFeeType");            
            TextBox txtFeeDesc = (TextBox)e.Row.FindControl("txtFeeDesc");     
            Button btnUpdate = (Button)e.Row.FindControl("btnUpdate");
        }
}

Comments

0

not only text box we can get values from all the controls that used inside gridview that placed by using itemTemplate or simply a Bound field .

you need to loop for each row to get the values

foreach (GridViewRow row in grd_popup_details.Rows)
 {
 //get control values
 }

Refference link

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.