Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 127673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:30:50+00:00 2026-05-11T05:30:50+00:00

I would like suggestions on how to inject a record into my DataList to

  • 0

I would like suggestions on how to inject a record into my DataList to give an ‘All’ option. Here is my code, data coming from the Northwind database.

<asp:DataList ID='DataList1' runat='server' DataSourceID='SqlDataSource1'          RepeatLayout='Flow' ShowFooter='False' ShowHeader='False'          RepeatDirection='Horizontal'          onitemcommand='DataList1_ItemCommand'>         <ItemStyle CssClass='datalist' />     <ItemTemplate>         <%#(((DataListItem)Container).ItemIndex+1).ToString() %>         <asp:LinkButton ID='lbtnRegion' runat='server'            Text='<%# Eval('RegionDescription').ToString().Trim() %>'         CommandName='<%# DataBinder.Eval(Container.DataItem,'RegionID')%>' />                         </ItemTemplate>            </asp:DataList>     <asp:SqlDataSource ID='SqlDataSource1' runat='server'      ConnectionString='<%$ ConnectionStrings:NorthwindConnectionString %>'      SelectCommand='SELECT [RegionID], [RegionDescription] FROM [Region]'          ondatabinding='SqlDataSource1_Databinding'      onselected='SqlDataSource1_Selected'> </asp:SqlDataSource> 

I am using the Link button in the Datalist to filter the territories and display them in a GridView. What I would like to do is at some in the databinding process, add an Item in the DataList that will act as the ALL option, any suggestions would be appreciated.

protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e) {     LinkButton lbtn;      foreach (DataListItem dli in DataList1.Items)     {         lbtn = (LinkButton)dli.FindControl('lbtnRegion');         if (lbtn != null)             lbtn.ForeColor = System.Drawing.Color.White;     }     string command = e.CommandName;     lbtn = (LinkButton)e.Item.FindControl('lbtnRegion');     if (lbtn != null)         lbtn.ForeColor = System.Drawing.Color.YellowGreen;      DataView dv = GetData(ref command); // Pass the RegionId     gvTerritory.DataSource = dv;     gvTerritory.DataBind(); } 

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T05:30:51+00:00Added an answer on May 11, 2026 at 5:30 am

    One way is to UNION ALL a ‘All’ value to the query fetching the list of drop down items.

    SELECT 'All', 'All Regions'  UNION ALL  SELECT [RegionID], [RegionDescription] FROM [Region] 

    But if you have a lot of lists (or dropdowns) like this, it is better practice to create a custom control that injects an ‘All’ record for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like suggestions on how to inject a record into my DropdownList to
I need some asp.net pagination code samples. I would like suggestions on open source
I have looked into both. Would like your suggestions as to which one is
I would like to receive suggestions on the data generators that are available, for
I would like your suggestions on how to proceed in making a control panel
Would like to parse IPv4 address from exit-addresses . Format of the file: ExitNode
I have a specific case here in which I would like some security advice.
I would like to make a vb .net application that auto logs into places
I'd like to use a tooltip as a toolbar and would like some suggestions
I would like to have suggestions as to how to use Qt to implement

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.