DropDown and ListBox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • murugavelmsc
    New Member
    • Apr 2008
    • 54

    DropDown and ListBox

    hi,
    in vs2005, i have a control of gridview and dropdown. in dropdown list have a item of table header which i configured in gridview.
    In Dropdown box, i selected one header means , it select the gridview particular column

    here the code i try,
    aspx
    Code:
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ProductID"
                DataSourceID="SqlDataSource1" PageSize="5">
                <Columns>
                    <asp:BoundField DataField="ProductID" HeaderText="ProductID" InsertVisible="False"
                        ReadOnly="True" SortExpression="ProductID" />
                    <asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" />
                </Columns>
            </asp:GridView>
            &nbsp;
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
                SelectCommand="SELECT * FROM [Current Product List]"></asp:SqlDataSource>
        
        </div>
            <asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
            </asp:DropDownList>
            <asp:Label ID="Label1" runat="server"></asp:Label>
        </form>
    
    </body>
    c#
    Code:
    protected void Page_Load(object sender, EventArgs e)
        {
            foreach (TableCell header in GridView1.HeaderRow.Cells)
            {
                DropDownList1.Items.Add(header.Text);
            }
            label1.Text = DropDownList1.Items.Count.ToString();
            a = DropDownList1.Items.Count.ToString();
        }
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int dd1=(GridView1.HeaderRow.FindControl("DropDowmList1"), DropDownList);
            
    
    
            
            Label1.Text = DropDownList1.Items.Count.ToString();
            Label1.Text = DropDownList1.SelectedIndex.ToString();
    
            
            //DropDownList1.SelectedItem.Value=
            
    
        }
    thanks,
    murugavel
    Last edited by Curtis Rutland; Jul 5 '08, 04:07 AM. Reason: Added code tags -- Please use the # button
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    Was there a question in there? You made statements and posted code, but there wasn't really a question.

    Also:

    Please enclose your posted code in [code] tags (See How to Ask a Question).

    This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

    Please use [code] tags in future.

    MODERATOR

    Comment

    Working...