开发者

How to use the GridView events

I have .aspx page . that Have the GridviewChild within another gridviewParent. My GridviewChild has Columns with some controls, out of which it has DropDown controls. I want to fill the Data in dropdowns

GridViewParent
           GridViewChild
                     Columns
                        DropDownControl

This is hierarchy that I want to explain. On wh开发者_如何学Goich event of which Grid I can do fillDropDown? Also how to get selected value (Which Events)? If possible send me code in C#


You can use RowDataBound event of the GridViewChild control to fill the drop down lists. To get the selected value of a drop down list u can say something like this:

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

I hope that was beneficial to u.


Bind the child gridview with parent data:

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

And then proceed to bind the DDL in the itemdatabound event:

.. 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
   }
}

You can also get the selected value in the same way, as mentioned in the other post.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜