如何使用GridView事件

时间:2010-01-18 07:23:36

标签: c# events

我有.aspx页面。将GridviewChild放在另一个gridviewParent中。我的GridviewChild有一些带有一些控件的列,其中有DropDown控件。我想在下拉列表中填写数据

GridViewParent
           GridViewChild
                     Columns
                        DropDownControl

这是我想要解释的层次结构。我可以在哪个Grid上执行fillDropDown的事件?另外如何获得选定的价值(哪些事件)?如果可能的话,请用C#发送代码

2 个答案:

答案 0 :(得分:0)

您可以使用GridViewChild控件的RowDataBound事件来填充下拉列表。 要获得下拉列表的选定值,您可以这样说:

DropDownList ddl = GridViewParent.GridViewChild.Rows[someRowIndex].Cells[someCellIndex].FindControl("DropDownlist1") as DropDownList;
string v = ddl.SelectedItem.Text;

我希望这对你有益。

答案 1 :(得分:0)

使用父数据绑定子gridview:

<ItemTemplate>
   <GridView id="childGrid" .. DataSource='<%# Eval("Items") %>' ItemDataBound="child_itemdatabound">
<ItemTemplate>

然后继续在itemdatabound事件中绑定DDL:

.. child_itemdatabound(..)
{
   DropDownList ddl = e.Row.FindControl("ddl") as DropDownList;
   if (ddl != null)
   {
      //Load from data source
      ddl.DataSource = dal.GetData();
      ddl.DataBind();

      //You can set the selected value here too; e.Row.DataItem represents the bound data object
   }
}

您也可以采用相同的方式获取所选值,如其他帖子所述。

相关问题