There does not seem to be a lot of info out there when using a GridView with AutoGenerateColumns="true"
.
In my scenario, I am attempting to use this because my GridView is dynamically pulling numeric values from a stored procedure. As you can see, there may be x number of tiers.
I have everything looking great when viewing the data:
Viewing only:
However, once I put the row into edit mode, things get like this:
Edit mode:
I need to do two things here:
- Make the TextBoxes smaller width
- Format the numbers to remove the decimals
I have researched looping through all of the controls inside a GridView row, inside DataControlField
, inside the DataControlFieldCell
but I have gotten confused enough to ask for everyone's help.
My code behind is in C#.
EDIT:
Ok, in an effort to be more clear, I am trying to click the edit (M button) to put the row into edit mode. From here, I would like to loop through all controls in the row and then set the TextBox width. Something along these lines (this is not working code but merely me messing around):
protected void gvFeeTable_RowEditing(object sender, GridViewEditEventArgs e)
{
gvFeeTable.EditIndex = e.NewEditIndex;
BindFeeTableGrid(9);
//foreach (DataControlField field in gvFeeTable.Columns)
//{
// field.ControlStyle.Width = 25;
//}
foreach (Control c in gvFeeTable.Rows[gvFeeTable.EditIndex].Controls)
{
//if (c is TextBox)
//{
// TextBox tb = c as TextBox;
// tb.Width = 25;
//}
string test = c.GetType().ToString();
if (c.GetType() == typeof(DataControlFieldCell))
{
foreach (TextBox tb in c.Controls)
{
tb.Width = 50;
}
}
}
}
Just wanted to post my solution for setting the size of the textbox...and adding in my code for formatting just to be complete:
Textboxes resized
Textboxes formatted