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
matthewskyle 0 Newbie Poster
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.
Example:
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.
xanawa -3 Junior Poster
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">
.style17
{
height: 23px;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder" Runat="Server">
<table style="width:100%;">
<tr>
<td class="style17">
<asp:Label ID="lblComment" runat="server" Font-Size="XX-Large" Text="Comments"></asp:Label>
</td>
</tr>
<tr>
<td>
<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:DropDownList>
<asp:SqlDataSource ID="dataSourceUsername" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [Username] FROM [tblMember]"></asp:SqlDataSource>
</td>
</tr>
<tr>
<td>
<asp:GridView ID="gvComments" runat="server" AutoGenerateColumns="False"
DataSourceID="dataSourceComments" style="text-align: center">
<Columns>
<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" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="dataSourceComments" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [Subject], [UserName], [Content], [DateAndTime] FROM [tblComment] WHERE ([UserName] = @UserName)">
<SelectParameters>
<asp:ControlParameter ControlID="dllusername" Name="UserName"
PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
</table>
</asp:Content>
chwong 0 Newbie Poster
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 & "' " & _
"ORDER BY ID"
AccessDataSource2.SelectCommand = SQLString
End Sub
</SCRIPT>
<asp:DropDownList ID="Category" runat="server" AutoPostBack="True"
DataSourceID="AccessDataSource1" DataTextField="Category"
DataValueField="Category" OnSelectedIndexChanged="Get_Category_Type">
</asp:DropDownList>
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.