mmedi005
asked on
How do I manipulate a control during the Databound event in a GridView?
How do I manipulate a control during the Databound event in a GridView?
I am doing this in the code below. How do I get this to work?
I am doing this in the code below. How do I get this to work?
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridViewRow row = e.Row;
int dataKeyIndex;
string address;
if (row.RowType == DataControlRowType.DataRow)
{
Panel p = (Panel)row.FindControl("uxAddressPanel");
dataKeyIndex = row.DataItemIndex;
address = GridView.DataKeys[dataKeyIndex].Values["Address"].ToString();
switch (row.RowState)
{
case DataControlRowState.Normal:
if ((address != null) && (address != ""))
p.Visible = true;
else
p.Visible = false;
break;
case (DataControlRowState.Edit | DataControlRowState.Selected):
RadioButtonList r = (RadioButtonList)row.FindControl("AddRadioButtonList");
if ((address != null) && (address != ""))
{
p.Visible = true;
r.SelectedValue = "True";
}
else
{
p.Visible = false;
r.SelectedValue = "False";
}
break;
}
}
}
ASKER
Your right...sorry...was in a hurry writing this....
It doesn't execute the switch statement.
It doesn't execute the switch statement.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The state is a bitwise combination...
So to check for a state you would use a bitwise comparison like this:
So to check for a state you would use a bitwise comparison like this:
if (row.RowState&DataControlRowState.Normal)
{
...
}
ASKER
>>Enum type sometimes don't work with switch statement. Why don't you just use if-else statement?
Tried and it still doesn't execute either condition
>>if (row.RowState&DataControlR owState.No rmal)
This fails
Any ideas?
Tried and it still doesn't execute either condition
>>if (row.RowState&DataControlR
This fails
Any ideas?
ASKER
>>if (row.RowState&DataControlR owState.No rmal)
{
...
}
I get this error:
Compiler Error Message: CS0029: Cannot implicitly convert type 'System.Web.UI.WebControls .DataContr olRowState ' to 'bool'
{
...
}
I get this error:
Compiler Error Message: CS0029: Cannot implicitly convert type 'System.Web.UI.WebControls
ASKER
k, got it to almost work...
used DataControlRowState.Altern ate with Normal to get these rows in a normal state,
But when I click Edit I get every other row to work...how do I get the Alternate row in Edit mode?
used DataControlRowState.Altern
But when I click Edit I get every other row to work...how do I get the Alternate row in Edit mode?
if (row.RowState == DataControlRowState.Normal || row.RowState == DataControlRowState.Alternate)
{
...
}
else if (e.Row.RowState == DataControlRowState.Edit)
{
...
}
Try "
if (row.RowState&DataControlR owState.No rmal == DataControlRowState.Normal )
...
if (row.RowState&DataControlR
...
ASKER
>>if (row.RowState&DataControlR owState.No rmal == DataControlRowState.Normal )
...
I get an error:
Compiler Error Message: CS0019: Operator '&' cannot be applied to operands of type 'System.Web.UI.WebControls .DataContr olRowState ' and 'bool'
When I click Edit. All odd rows are executing the statements within the if statement. All even rows are not.
This is when I have the code below as the if statement.
...
I get an error:
Compiler Error Message: CS0019: Operator '&' cannot be applied to operands of type 'System.Web.UI.WebControls
When I click Edit. All odd rows are executing the statements within the if statement. All even rows are not.
This is when I have the code below as the if statement.
if (row.RowState == DataControlRowState.Edit)
{
....
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
That error are you getting?