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 4604902
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:21:33+00:00 2026-05-22T00:21:33+00:00

I have got a datalist with some databound fields with 2 buttons. I want

  • 0

I have got a datalist with some databound fields with 2 buttons. I want to enable disable button depending on the column(state) value of each row, so for instance if the value of state is 0 , the remove button should be disable and add button should be enabled similarly when the value of state is 1 , vice versa..

protected void dlEditCaravans_ItemDataBound(object sender, DataListItemEventArgs e)
{
    Button addtoFeauture = e.Item.FindControl("btnAddToFeature") as Button;
    Button removetoFeauture = e.Item.FindControl("btnRemoveFeature") as Button;
    int id = Convert.ToInt32(dlEditCaravans.DataKeys[e.Item.ItemIndex]);
    int check = caravans.GetfeautureValue(id);

    if (check == 0)
    {
        addtoFeauture.Enabled = true;

    }

    else
    {
        removetoFeauture.Enabled = true;

    }

  }

I have tried something like above but it gives object reference not set to an instance error.

  • 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. Editorial Team
    Editorial Team
    2026-05-22T00:21:34+00:00Added an answer on May 22, 2026 at 12:21 am

    You need to use ItemDatabound event of Datalist

    protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
     if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
        {
            DataRow dr = ((DataRowView)e.Item.DataItem).Row;
            if (Convert.ToBoolean(dr["StateColumnName"])
            {
              ((Button)e.Item.FindControl("Button1")).Enable = True;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got some excel sheet and want to fill fields automaticly with data.
I have got a List<Problem> which I want to export to a column based
I have got 2 check box[isSold(bit), Offline(bit)] in the datalist , I want to
I have got some code to load an assembly and get all types, which
I have got a table in MS Access 2007 with 4 fields. Labour Cost
Hey guys I got a weird issue.. I have a datalist that's only loaded
I have got ListView with a custom Adapter. Every row contains clickable buttons and
i have got a function with BOOL return value and 2 input (NSDateComponents *)
I have got the array containing some data, say, a header and a real
i have got a code to edit some function. There is a text box

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.