Click here to Skip to main content
14,865,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to Bind my Gridview on Selected Index change.. I dont know why am i stuck in this simple issue.. My Code:
C#
protected void DropDownListHostelRoom_SelectedIndexChanged(object sender, EventArgs e)
           {
               if (DropDownListHostelRoom.SelectedValue == "Single")
               {
                   SqlConnection cn = new SqlConnection(@"Data Source=.;Initial Catalog=_uniManagement;Integrated Security=True");
                   string sql = "select HRName,Booked,_Issued from _hostel_room where booked = 'NO' and _issued = 'NO' and _hrtypid = 1";
                   SqlCommand cmd = new SqlCommand(sql, cn);
                   SqlDataAdapter da = new SqlDataAdapter(cmd);
                   DataTable dt = new DataTable();
                   da.Fill(dt);
                   GridViewHostelRoom.DataSource = dt;
                   GridViewHostelRoom.DataBind();
                   UpdatePanel1.DataBind();

               }
   }


<pre lang="xml"><asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <asp:ScriptManager ID="ScriptManagerMemberType" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanelMemberType" runat="server">
        <ContentTemplate>
            <div>
                <fieldset>
                    <legend>Create Hostel Member</legend>
                    <asp:Label ID="LabelMemberType" runat="server" Text="Member Type"></asp:Label>&nbsp
                    <asp:DropDownList ID="DropDownListMemberType" AutoPostBack="true" runat="server"
                        DataTextField="HMemTypeName" DataValueField="_HMemTypeID" OnSelectedIndexChanged="DropDownListMemberType_SelectedIndexChanged">
                    </asp:DropDownList>
                    <br />
                    <asp:Label ID="LabelMemberName" runat="server" Text="Search"></asp:Label>
                    <asp:TextBox ID="TextBoxMemberName" runat="server" OnTextChanged="TextBoxMemberName_TextChanged"></asp:TextBox><br />
                    <asp:GridView ID="GridViewMemberType" runat="server" AutoGenerateColumns="False"
                        Style="margin-right: 0px" DataKeyNames="_PersID">
                        <Columns>
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <asp:CheckBox ID="CheckBoxMemberType" runat="server" OnCheckedChanged="CheckBoxMemberType_CheckedChanged" />
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:BoundField DataField="FirstName" />
                            <asp:BoundField DataField="LastName" />
                            <asp:BoundField DataField="DOB" />
                            <asp:BoundField DataField="FatherName" />
                            <asp:BoundField DataField="Nationality" />
                        </Columns>
                    </asp:GridView>
                    <asp:Button ID="ButtonHostelMember" runat="server" Text="Create Hostel Member" OnClick="ButtonHostelMember_Click" />
                    <asp:Label ID="LabelTemporaryID" runat="server" Text=""></asp:Label>
                </fieldset>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <div>
                <fieldset>
                    <legend>Hostel Details </legend>
                    <asp:Label ID="LabelHostelRoomType" runat="server" Text="Room Type"></asp:Label>
                    <asp:DropDownList ID="DropDownListHostelRoom" runat="server" DataTextField="HTypeName"
                        DataValueField="_HRTypID" OnSelectedIndexChanged="DropDownListHostelRoom_SelectedIndexChanged">
                    </asp:DropDownList>
                    <asp:GridView ID="GridViewHostelRoom" runat="server">
                        <Columns>
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <asp:LinkButton ID="LinkButtonRoomIssue" runat="server">Click To Issue</asp:LinkButton>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
                </fieldset>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
Posted
Updated 23-Mar-12 21:55pm
v3
Comments
Abid A 24-Mar-12 2:14am
   
and also when i do debugging, the event doesnt even fires :/

1 solution

just add Trigger to ur update panel

XML
<Triggers>
            <asp:AsyncPostBackTrigger ControlID="DropDownListHostelRoom"
                EventName="SelectedIndexChanged" />
</Triggers>


you forget Autopostback
:)
SQL
<asp:DropDownList ID="DropDownListHostelRoom" runat="server" DataTextField="HTypeName"
                    DataValueField="_HRTypID"
                    OnSelectedIndexChanged="DropDownListHostelRoom_SelectedIndexChanged"
                    AutoPostBack="True">
   
v2
Comments
Abid A 24-Mar-12 3:25am
   
it doesnt even works as well. :/
Mohamed Mitwalli 24-Mar-12 5:37am
   
it work with me .
Mohamed Mitwalli 24-Mar-12 11:39am
   
you forget Autopostback

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900