Access DropDownList in EditItemTemplate within GridView on GridView_RowEditing
I inserted a DropDownList into an EditItemTemplate within a GridView and I'd like to fill this DropDownList with Items based on a Value in another GridView-Column on the same row.
Let me give you an example:
If the row looks like this:
Itemname, string, TextBox, (editbutton)
I want the click on EditButton to transform the string "TextBox" into a DropDownList with the Options "TextBox" or "DropDownList", but if the row looks like this:
Itemname, bool, CheckBox, (editbutton)
I want the DropDown to only feature "CheckBox" and "RadioButton".
So, logically, I need to access a) the Column containing the value of the datatype-field (string or bool) and b) access the DropDown-List to modify its items within the GridView_RowEditing-Event.
I already managed doing a), can anyone help me with b)?
My Code currently looks like this:
protected void gridVariables_RowEditing(object sender, GridViewEditEventArgs e)
{
switch (gridVariables.Rows[e.NewEditIndex].Cells[2].Text)
{
case "string":
case "double":
case "long":
break;
case "bool":
break;
default:
开发者_运维知识库 break;
}
gridVariables.EditIndex = e.NewEditIndex;
gridVariables_DataBind();
}
Thanks,
Dennis
Since you did not post the gridview code ill just do this in psuedo code
In your rowdatabound Event handler
Check if the row is the edit row
ddl.Items.Clear()
if (dataitem is textbox or ddl)
ddl.items.add("textBox");
ddl.items.add("DDL");
else
ddl.items.add("CB");
ddl.items.add("RB");
精彩评论