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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:13:05+00:00 2026-05-15T19:13:05+00:00

I need code example please.i tried selectedindexchange but it doesnot register any index change

  • 0

I need code example please.i tried selectedindexchange but it doesnot register any index change what to use?

its c# vs08 asp.net sql server

the code files are

.cs file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {





    }
    protected void Button1_Click(object sender, EventArgs e)
    {//not this
        ///Label3.Text = "clicked clicked clicked";


    }
    protected void Button1_Click1(object sender, EventArgs e)
    {

        Label5.Text = "the tool tip of the button clicked is! HELP!!!";


        //here code please how to which button is clicked?
        //there are many records so?
        //even if i try to use the button id directly
        //it does not appear
        //to vs the button does not exist outside the datalist control
        //help

    }
}

the source file

    <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
        ConnectionString="<%$ ConnectionStrings:test1 %>" 
        DeleteCommand="DELETE FROM [1] WHERE [ID] = @ID" 
        InsertCommand="INSERT INTO [1] ([ID], [NAME]) VALUES (@ID, @NAME)" 
        SelectCommand="SELECT * FROM [1]" 
        UpdateCommand="UPDATE [1] SET [NAME] = @NAME WHERE [ID] = @ID">
        <DeleteParameters>
            <asp:Parameter Name="ID" Type="Decimal" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="NAME" Type="String" />
            <asp:Parameter Name="ID" Type="Decimal" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="ID" Type="Decimal" />
            <asp:Parameter Name="NAME" Type="String" />
        </InsertParameters>
    </asp:SqlDataSource>
<br />
    <asp:Label ID="Label5" runat="server" Text="Label"></asp:Label>
    <br />
    <asp:DataList ID="DataList2" runat="server" DataKeyField="ID" 
        DataSourceID="SqlDataSource3">
        <ItemTemplate>
            ID:
            <asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' />
            <br />
            NAME:
            <asp:Label ID="NAMELabel" runat="server" Text='<%# Eval("NAME") %>' />
            <br />
            <br />
            <asp:Label ID="Label1" runat="server" Text='<%# Eval("ID") %>'></asp:Label>
            -<asp:Label ID="Label2" runat="server" Text='<%# Eval("NAME") %>'></asp:Label>
            &nbsp;
            <br />
            <br />
            <br />
            &nbsp;<asp:Label ID="Label4" runat="server" Text='<%# Eval("ID") %>' 
                ToolTip='<%# Eval("NAME") %>'></asp:Label>
            <br />
            here extra information/ description is binded to tool tip.<br />
            <br />
            <br />
            <asp:Button ID="Button1" runat="server" onclick="Button1_Click1" 
                Text='<%# Eval("ID") %>' ToolTip='<%# Eval("NAME") %>' />
            <br />
            when clicked, the text of the button is displayed in the label. but many records 
            so button belonging to which record clicked?<br />
            <br />
            <br />
            <hr />
            <br />
            <br />
        </ItemTemplate>
    </asp:DataList>
    <br />

 


EDIT

<asp:DataList ID="DataList2" runat="server" DataKeyField="ID" 
        DataSourceID="SqlDataSource3">
        <ItemTemplate>
            ID:
            <asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' />
            <br />
            NAME:
            <asp:Label ID="NAMELabel" runat="server" Text='<%# Eval("NAME") %>' />
            <br />
            <br />
            <asp:Label ID="Label1" runat="server" Text='<%# Eval("ID") %>'></asp:Label>
            -<asp:Label ID="Label2" runat="server" Text='<%# Eval("NAME") %>'></asp:Label>
            &nbsp;
            <br />
            <br />
            <br />
            &nbsp;<asp:Label ID="Label4" runat="server" Text='<%# Eval("ID") %>' 
                ToolTip='<%# Eval("NAME") %>'></asp:Label>
            <br />
            here extra information/ description is binded to tool tip.<br />
            <br />
            <br />
            <asp:Button ID="Button1" runat="server" onclick="Button1_Click1" 
                Text='<%# Eval("ID") %>' ToolTip='<%# Eval("NAME") %>' />
            <br />
            when clicked, the text of the button is displayed in the label. <br />
            <br />
            <br />
            <asp:Button ID="Button2" runat="server" CommandArgument='<%# Eval("NAME") %>' 
                CommandName="Explain" Text='<%# Eval("ID") %>' />
            <asp:TextBox ID="TextBox1" runat="server">First Record</asp:TextBox>
            <br />
            when clicked takes argument from button and the text in the text box, displayed. 
            (record 1)<br />
            <br />
            <br />
            <br />
            <asp:Button ID="Button3" runat="server" CommandArgument='<%# Eval("NAME") %>' 
                CommandName="Explain" Text='<%# Eval("ID") %>' />
            //<br />
            when clicked does the same as above
            <br />
            <hr />
            <br />
            <br />
        </ItemTemplate>
    </asp:DataList>

code behind

protected void DataList2_ItemCommand(object sender, DataListCommandEventArgs e)
{
// all of the buttons within the row that have the CommandName property set can cause this event handler to execute.
// Use the CommandName argument to determine which button was clicked and take the appropriate action
switch (e.CommandName)
{

        case "Explain":
            // update your label using the command argument rather that the button's ToolTip
            Label5.Text = e.CommandArgument.ToString();

            TextBox TextBox1 = e.Item.FindControl("TextBox1") as TextBox;

            Label6.Text = TextBox1.Text;

            break;



        default:
            Label5.Text="ERROR";
            break;
    }
}

mistake:- i forgot to put
OnItemCommand=”MyDataList_ItemCommand”
in datalist source code
…

  • 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-15T19:13:05+00:00Added an answer on May 15, 2026 at 7:13 pm

    You could do this:

    protected void Button1_Click1(object sender, EventArgs e)
    {
        Label5.Text = (sender as Button).ToolTip;
    }
    

    Also, if you know that you want to work with other controls within that row, you could use the DataList.ItemCommand event instead of the Button.Click event. Below is an example of how you might do that:

    ASP Markup:

            <asp:Label ID="MyLabel" runat="server" />
            <asp:DataList ID="MyDataList" runat="server" OnItemCommand="MyDataList_ItemCommand">
                <ItemTemplate>
                    <!-- Suppose you had some input controls that you needed to work with as well -->
                    <asp:TextBox ID="txtInput1" runat="server" />
                    <asp:TextBox ID="txtInput2" runat="server" />
                    <asp:Button ID="btnMyCommand" runat="server" CommandName="MyCommand" CommandArgument='<%# Eval("NAME") %>' Text='<%# "Execute My Command on ID:" + Eval("ID") %>' ToolTip='<%# string.Format("This will execute the \"My Command\" command on {0}.", Eval("NAME")) %>' />
                    <!-- just some examples of other buttons on the same row that execute different commands -->
                    <asp:Button ID="btnDoSomethingCrazy" runat="server" CommandName="Do Something Crazy!" Text="Do Something Crazy!" />
                    <asp:LinkButton ID="btnEdit" runat="server" CommandName="Edit" Text="Edit" />
                </ItemTemplate>
            </asp:DataList>
    

    Code-Behind:

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack && !Page.IsCallback)
            {
                // some example data
                MyDataList.DataSource = new[] {
                    new { ID = 1, NAME = "ABCD" },
                    new { ID = 2, NAME = "BCDE" },
                    new { ID = 3, NAME = "CDEF" },
                };
                MyDataList.DataBind();
            }
        }
    
        protected void MyDataList_ItemCommand(object sender, DataListCommandEventArgs e)
        {
            // all of the buttons within the row can cause this event handler to execute.
            // Use the CommandName argument (populated by the CommandName property of the button that was clicked) in order to determine which button was clicked and take the appropriate action
            switch (e.CommandName)
            {
                case "Edit":
                    // ...
                    break;
                case "Update":
                    // ...
                    break;
                case "Cancel":
                    // ...
                    break;
                case "Delete":
                    // ...
                    break;
                case "MyCommand":
                    // update your label using the command argument rather that the button's ToolTip
                    MyLabel.Text = e.CommandArgument.ToString();
    
                    TextBox txtInput1 = e.Item.FindControl("txtInput1") as TextBox;
                    TextBox txtInput2 = e.Item.FindControl("txtInput2") as TextBox;
    
                    string value1 = txtInput1.Text;
                    string value2 = txtInput2.Text;
    
                    // do something with the input values
                    break;
                case "Do Something Crazy!":
                    // ...
                    break;
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 461k
  • Answers 461k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The code provided should be considered a sketch rather than… May 16, 2026 at 12:01 am
  • Editorial Team
    Editorial Team added an answer It sounds like you're looking for a type of file… May 16, 2026 at 12:01 am
  • Editorial Team
    Editorial Team added an answer Pathway Systems sells such a tool for modeling and maintaining… May 16, 2026 at 12:01 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.