I have a combobox filled with usernames from teh database. And i have a gridview that display's the comments from database depending what username was choosed from combobox

7 Years
Discussion Span
Last Post by chwong

Is there a question hidden in there? Ill take a stab and guess you want to display the comments in the gridview based on what the end-user selects in the DDL. If that's the case simply put @field_name in you where clause of the datasource.


ddlUsername SQL- SELECT * from table
gridview SQL- SELECT user_comments from table where user_id = @user_id;

After you input the SQL for the gridview you will come to a screen where you define parameters (user_id). Set it to control & then select the name of your DDL.

If thats not what you were asking. Oh well.


i have this code.. but still when i change the value from th dll th data in the gridview does not change

<%@ Page Language="C#" MasterPageFile="~/PgMain.master" AutoEventWireup="true" CodeFile="PgComments.aspx.cs" Inherits="PgComments" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <style type="text/css">
            height: 23px;
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder" Runat="Server">
    <table style="width:100%;">
            <td class="style17">
                <asp:Label ID="lblComment" runat="server" Font-Size="XX-Large" Text="Comments"></asp:Label>
                <asp:Label ID="lblUsername" runat="server" Font-Size="Medium" Text="Username:"></asp:Label>
                <asp:DropDownList ID="dllusername" runat="server" 
                    DataSourceID="dataSourceUsername" DataTextField="Username" 
                    DataValueField="Username" Height="25px" Width="168px">
                <asp:SqlDataSource ID="dataSourceUsername" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
                    SelectCommand="SELECT [Username] FROM [tblMember]"></asp:SqlDataSource>
                <asp:GridView ID="gvComments" runat="server" AutoGenerateColumns="False" 
                    DataSourceID="dataSourceComments" style="text-align: center">
                        <asp:BoundField DataField="Subject" HeaderText="Subject" 
                            SortExpression="Subject" />
                        <asp:BoundField DataField="UserName" HeaderText="UserName" 
                            SortExpression="UserName" />
                        <asp:BoundField DataField="Content" HeaderText="Content" 
                            SortExpression="Content" />
                        <asp:BoundField DataField="DateAndTime" HeaderText="DateAndTime" 
                            SortExpression="DateAndTime" />
                <asp:SqlDataSource ID="dataSourceComments" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
                    SelectCommand="SELECT [Subject], [UserName], [Content], [DateAndTime] FROM [tblComment] WHERE ([UserName] = @UserName)">
                        <asp:ControlParameter ControlID="dllusername" Name="UserName" 
                            PropertyName="SelectedValue" Type="String" />

Please try below code. It should able to solve your problem.
<SCRIPT Runat="Server">

Sub Get_Category_Type(ByVal Src As Object, ByVal Args As EventArgs)

Dim SQLString As String
SQLString = "SELECT * FROM products " & _
"WHERE Category = '" & Category.SelectedValue & "' " & _
AccessDataSource2.SelectCommand = SQLString

End Sub


<asp:DropDownList ID="Category" runat="server" AutoPostBack="True"
DataSourceID="AccessDataSource1" DataTextField="Category"
DataValueField="Category" OnSelectedIndexChanged="Get_Category_Type">

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.