I have an asp.net web page. In it, I have a gridview using a linq to sql data source.
The gridview is databound to a table in sql. I need to add several dropdownlists to filter the view of the gridview. I add one dropdownlist and populate it. How do I get the ddlComment to filter the GridViewUG? The datakey for GridViewUG is ref_id, but I need the dropdown to show Comment and allow selection of Comment.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection Conn3 = new SqlConnection(MyGlobals.ConnString);
SqlDataAdapter da3 = new SqlDataAdapter("select distinct comment from cap.manual_adjustments", Conn3);
DataSet ds3 = new DataSet();
da3.Fill(ds3);
if (ddlComment != null)
{
ddlComment.DataSource = ds3;
ddlComment.DataTextField = "Comment";
ddlComment.DataValueField = "Comment";
ddlComment.Items.Insert(0, new ListItem("Select"));
ddlComment.DataBind();
}
}
}
<asp:GridView ID="GridViewMA" runat="server" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="dsManualAdjustments"
Height="100%" Width="100%"
ShowFooter="True"
DataKeyNames="Ref_Id"
OnSelectedIndexChanged="SelectedIndexChanged"
OnRowEditing="OnRowEditing"
OnRowCancelingEdit="OnRowCanceling"
DataBindingComplete="DataBindingComp"
EnableDelete="true">
<AlternatingRowStyle BackColor="#cccccc" />
<%-- <HeaderStyle CssClass="GVFixedHeader" />
<FooterStyle CssClass="GVFixedFooter" />--%>
<Columns>
<asp:CommandField ShowEditButton="True"
ButtonType="Link" EditText="<img src='Images/edit2.png' border=0 title='Edit the Row'>"
UpdateText="<img src='Images/update2.png' border=0 title='Update the Row'>"
CancelText="<img src='Images/cancel2.png' border=0 title='Cancel your changes'>">
</asp:CommandField>
<asp:TemplateField ShowHeader="false">
<ItemTemplate>
<asp:imagebutton ID="LinkButton2" runat="server" CommandName="Delete" imageurl="~/Images/delete2.png" OnClientClick="return confirm('Delete this entry?');" ToolTip='Delete the Row'></asp:imagebutton>
</ItemTemplate>
<ItemStyle Width="25px" />
</asp:TemplateField>
<asp:TemplateField ShowHeader="false">
<ItemTemplate>
<asp:imagebutton ID="LinkButton3" runat="server" CommandName="Copy" imageurl="~/Images/copy2.png"
OnClick="CopyRow"
ToolTip='Copy the Row' ></asp:imagebutton>
</ItemTemplate>
<ItemStyle Width="25px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Action" ItemStyle-Width="25px">
<ItemTemplate>
</ItemTemplate>
<FooterStyle HorizontalAlign="Left" />
<FooterTemplate>
<asp:Button ID="ButtonAdd" runat="server" Text="Add" OnClick="FirstGridViewRow" />
<asp:Button ID="ButtonUpload" runat="server" Text="Upload" OnClick="btnUpload_Click" />
</FooterTemplate>
<ItemStyle HorizontalAlign="Left" Width="25px" />
</asp:TemplateField>
<asp:BoundField DataField="Import_Date" HeaderText="Import_Date" ReadOnly="True" SortExpression="Import_Date" />
.
.
.
<asp:TemplateField HeaderText="LC_Balance" ItemStyle-Width="100px" SortExpression="LC_Balance">
<ItemTemplate>
<asp:label ID="LCBalance" runat="server" Text='<%# Eval("LC_Balance") %>' width="100px"></asp:label>
</ItemTemplate>
<EditItemTemplate>
<asp:textbox ID="LCBalance" runat="server" Text='<%# Bind("LC_Balance")%>' Visible="true" ReadOnly="false" Width="150px" MaxLength="15"></asp:textbox>
</EditItemTemplate>
<FooterStyle HorizontalAlign="Right" BackColor="Blue"/>
<FooterTemplate>
<asp:Textbox ID="LCBalance" runat="server" Text='<%# Eval("LC_Balance") %>' width="100px" MaxLength="15"/>
</FooterTemplate>
<ItemStyle HorizontalAlign="Left" Width="100px" />
</asp:TemplateField>
<%-- <asp:BoundField DataField="User_Id" HeaderText="User_Id" ReadOnly="True" SortExpression="User_Id" />
<asp:BoundField DataField="Modified" HeaderText="Modified" ReadOnly="True" SortExpression="Modified" />
<asp:BoundField DataField="Import_Date" HeaderText="Import_Date" ReadOnly="True" SortExpression="Import_Date" />--%>
</Columns>
</asp:GridView>
</div>
<asp:LinqDataSource ID="dsManualAdjustments" runat="server" ContextTypeName="CAPScheduler.ManualAdjustmentsDataContext" EntityTypeName="" TableName="Manual_Adjustments" Select="new (Comment, Entity_Number, Ref_Id)" Where="Comment == @Comment" >
<WhereParameters>
<asp:ControlParameter ControlID="ddlComment" Name="Comment" PropertyName="SelectedValue" Type="String" />
</WhereParameters>
</asp:LinqDataSource>
What I have tried:
I tried creating a dropdown list with linq and attaching the 2 in design mode, but I want a distinct line for each group of a comment. It returns multiple lines for the same comment, because it is really relating the dropdownlist with the gridview in the background by ref_id