Populate a second drop down list upon selection value of the first drop down list in a gridview

How to Populate a second drop down list upon selection value of the first drop down list in a gridview?

DropDownList1

*******************

<asp:TemplateField HeaderText="SystemName" SortExpression="SystemName">
                <EditItemTemplate>
                    <asp:DropDownList ID="sysidddl" runat="server" DataSourceID="sysods1"
                        DataTextField="SystemName" DataValueField="SystemName">
                    </asp:DropDownList><asp:ObjectDataSource ID="sysods1" runat="server" OldValuesParameterFormatString="original_{0}"
                        SelectMethod="GettblTSystems" TypeName="tblTSystemsBLL"></asp:ObjectDataSource>
                    &nbsp;&nbsp;
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("SystemName") %>'></asp:Label>
                </ItemTemplate>
                <FooterTemplate>
                    <asp:DropDownList ID="NewSystemName" runat="server" DataSourceID="sysODS2"
                        DataTextField="SystemName" DataValueField="SystemName">
                    </asp:DropDownList><asp:ObjectDataSource ID="sysODS2" runat="server" OldValuesParameterFormatString="original_{0}"
                        SelectMethod="GettblTSystems" TypeName="tblTSystemsBLL"></asp:ObjectDataSource>
                    &nbsp;
                </FooterTemplate>
            </asp:TemplateField>

DropDownList2

******************
            <asp:TemplateField HeaderText="SubSystem" SortExpression="SubSystem">
                <EditItemTemplate>
                    &nbsp;<asp:DropDownList ID="subsysddl" runat="server" DataSourceID="SubSysODS"
                        DataTextField="SubSystem" DataValueField="SubSystem">
                    </asp:DropDownList><asp:ObjectDataSource ID="SubSysODS" runat="server" OldValuesParameterFormatString="original_{0}"
                        SelectMethod="GettblSubSystemBySystemID" TypeName="tblSubSystemBLL">
                        <SelectParameters>
                            <asp:Parameter Name="SystemID" Type="Int32" />
                        </SelectParameters>
                    </asp:ObjectDataSource>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label3" runat="server" Text='<%# Bind("SubSystem") %>'></asp:Label>
                </ItemTemplate>
                <FooterTemplate>
                    &nbsp;<asp:DropDownList ID="NewSubSystem" runat="server" DataSourceID="subsysddlODS2"
                        DataTextField="SubSystem" DataValueField="SubSystem">
                    </asp:DropDownList><asp:ObjectDataSource ID="subsysddlODS2" runat="server" OldValuesParameterFormatString="original_{0}"
                        SelectMethod="GettblSubSystem" TypeName="tblSubSystemBLL"></asp:ObjectDataSource>
                </FooterTemplate>
            </asp:TemplateField>


ptown
0
ptown
3/6/2008 8:38:50 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

2 Replies
1461 Views

Similar Articles

[PageSpeed] 14

from source, add a selectedindexchanged event handler to ddl in gridview. handle the event in code behind

 

in that event,

 

for(int vLoop=0 ; vLoop <grid1.rows.count;vLoop++)

{

Dropdwonlist ddl1 =  (Dropdownlist) grid1.rows[vloop].FindCOntrol("sysidddl");

if(ddl1 = (Dropdownlist)sender)

{

// FIndout the second ddl using same findcontrol method as above.

// Fetch the data u required by sending value of first ddl.

// Fill the data to 2nd ddl

}

}


Give a man a fish and you feed him for a day. Teach a man to fish and you feed him forever.
0
ramireddyindia
3/8/2008 2:10:31 PM

Ok this i what I now have:

Protected Sub sysidddl_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

For vLoop As Integer = 0 To GridView1.Rows.Count - 1

Dim ddl1 As DropDownList = DirectCast(GridView1.Rows(vLoop).FindControl("sysidddl"), DropDownList)

'If ddl1 = DirectCast(sender, DropDownList) As System.Web.UI.WebControls.DropDownList Then

' Findout the second ddl using same findcontrol method as above.

Dim ddl2 As DropDownList = DirectCast(GridView1.Rows(vLoop).FindControl("subsysddl"), DropDownList)

' Fetch the data u required by sending value of first ddl.

ddl1 = CType(GridView1.FindControl("subsysddl"), System.Web.UI.WebControls.DropDownList)

' Fill the data to 2nd ddl

ddl2.DataBind()

 

'End If

Next

End Sub


ptown
0
ptown
3/8/2008 6:56:32 PM
Reply:

Web resources about - Populate a second drop down list upon selection value of the first drop down list in a gridview - asp.net.presentation-controls

Selection - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Megan Jones is seeking a faster cross country time to boost hopes of Olympic selection - AdelaideNow ...
SOUTH Australian Megan Jones had a simple wish on the eve of the talent-laden four-star competition at the Adelaide International Three Day Event. ...

Tinkoff Saxo's Michael Rogers aiming for Rio Olympics selection before retiring
Veteran cyclist will retire at the end of 2016, with the Tour de France and Olympics his focus.

Australian cricket's most surprising Test selections
While Nathan Coulter-Nile's selection for Australia's Test cricket squad was a surprise, it's hardly the first the Aussie selectors have sprung ...

The Law Firm Selection Guide
Download our Law Firm Selection Guide.

Jury Selection Begins for Officer Charged in Gray's Death
CBS Local Jury Selection Begins for Officer Charged in Gray's Death CBS Local BALTIMORE (WNEW/AP) — Jury selection for the first police officer ...

Jury selection to begin in first Freddie Gray trial
Officer William Porter could spend at least 10 years in prison if convicted for his alleged role in the death of the 25-year-old black man

Cubs' Kris Bryant unanimous selection as NL Rookie of the Year
Chicago Tribune Cubs' Kris Bryant unanimous selection as NL Rookie of the Year Chicago Tribune Bryant, 23, set franchise rookie records with ...

Jury selection begins in the first of six trials in Freddie Gray case
... in the back of a police van, the trial for the first of six Baltimore police officers accused of killing him is officially underway. Jury selection ...

The Latest on Freddie Gray: Jury Selection in Officer Trial
The Latest: Jury selection in its 2nd day for officer's trial over death of Freddie Gray

Resources last updated: 12/3/2015 6:20:29 PM