I have parent gridview and child gridview, In child gridview I have one dropdown list, I need to fire the onselectedindexchanged event for that drop down but it is not firring because it is existed in the child gridview. If I place that dropdown in parent gridview then that selectedindexchanged is firing but I want to place that dropdown in child gridview and need to fire onselectedindexchanged event when user change the dropdown list value . In the below gridview image you can see the Status column in child gridview. It contains dropdown now I want to fire that dropdown seleted index changed event in code behind.
<asp:GridView ID="gvCountry" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<img alt="" id="imgsymbol" style="cursor: pointer" src="images/plus.png" />
<asp:Panel ID="pnlOrders" runat="server" Style="display: none">
<asp:GridView ID="gvBrokerdetails" runat="server" AutoGenerateColumns="false" CssClass="mGrid" OnRowCommand="gvBrokerdetails_RowCommand"
AlternatingRowStyle-CssClass="alt" PagerStyle-CssClass="pgr" GridLines="None" AllowPaging="true">
<Columns>
<asp:BoundField DataField="BrokerName" HeaderText="Name" />
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
<asp:DropDownList ID="ddlStatus" runat="server" OnSelectedIndexChanged="ddlStatus_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem Text="Include" Value="0"></asp:ListItem>
<asp:ListItem Text="Exclude" Value="1"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:ImageButton ID="imgBtnDeleteRow" runat="server" Width="25px" Height="25px" CommandName="CrossImageButton" CommandArgument='<%#Eval("BrokerId")%>' ImageUrl="~/images/cross-button.png" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="CountryName" HeaderText="Country Name" />
</Columns>
</asp:GridView>
CodeBehind:
public void ddlStatus_SelectedIndexChanged(object sender, EventArgs e)
{
}
But the above is event is not calling. Is there any other process to achieve or I need to specify any new property in the code.
Find your gridview inside the RowDataBound Event of parent gridview
protected void gvCountry_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
GridView mygrid = e.Row.FindControl("gvBrokerdetails") as GridView;
}
}
than handle the event of mygrid
it is your child grid you can handle any event you want or assign any property to it. an example of Selected_IndexChanged
is below
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridView mygrid = e.Row.FindControl("gvBrokerdetails") as GridView;
mygrid.SelectedIndexChanged += new EventHandler(mygrid_SelectedIndexChanged);
}
}
void mygrid_SelectedIndexChanged(object sender, EventArgs e)
{
// Write your code here
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.