That is an explicit cast. Basically you are forcing the cpu to consider the control that is found on the grid to be a textbox. This is because the FindControl() function returns an object of type Control. A textbox is derived from a Control so the cast works, and is required since not every Control contains a .Text member. Hope this helps a bit :)
i didnt understand a bit :(
Are you familiar with polymorhpism, .net, or casting?
i know casting ...changing int to string
Ok. I will break it down for you
grid.Rows is a collection of row objects
these objects can be referenced by their index: [e.RowIndex]
a grid row can contain a control
the control can be referenced via the FindControl(string control_name) function
the Control class is the base class for all controls, and since TextBox is a control it inherits the Control class. Because of this, the textbox can be explicitly cast out of the control referenced by the FindControl function. In C# explicit casting is done by placing the object type that you would like to cast in brackets beside the object to be casted. That is what the (TextBox) is doing. It may be easier to think about if it is spaced out into individual lines (since quite a bit is actually ocurring on that one line)
//Variable to hold the name string name; //Reference to the control to extract from the gridview row Control tempControl; //Reference to the textbox to cast from the control that is extracted from the gridview row TextBox tempTextBox; //Reference to the gridview row itself GridViewRow tempRow; //Get the row (assume e.RowIndex is defined - probably an event arg) tempRow = grid.Rows[e.RowIndex]; //Find the control called "nameTextBox" in that gridview row //Note that a Control class does not have a .Text property, so it must be cast into //a textbox (since that is what the control actually is) tempControl = tempRow.FindControl("nameTextBox"); //cast the control into a textbox explicitly tempTextBox = (TextBox)tempControl; //Get the name out of the textbox's text property name = tempTextBox.Text;
It's a bit late for me to try and teach a coding lesson. Hope this helps you though.
Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...
Hi. so this is actually a continuation from another question of mineHere but i was advised to start a new thread as the original question was already answered.
This is the result of previous question answered :
code for the listbox - datagridview interaction
At the top of the code ...
I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...