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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:04:07+00:00 2026-05-14T00:04:07+00:00

I have a datalist control <asp:DataList ID=DataList1 runat=server DataKeyField=AdmissionNo OnCancelCommand=DataList1_CancelCommand1 OnEditCommand=DataList1_EditCommand1 OnUpdateCommand=DataList1_UpdateCommand1 Width=300px> <ItemTemplate>

  • 0

I have a datalist control

  <asp:DataList ID="DataList1" runat="server" DataKeyField="AdmissionNo" OnCancelCommand="DataList1_CancelCommand1"
            OnEditCommand="DataList1_EditCommand1" OnUpdateCommand="DataList1_UpdateCommand1"
            Width="300px">

            <ItemTemplate>
                <tr>
                    <td height="31px">
                        <asp:Label ID="lblStudentName" runat="server" Text="StudentName :" Font-Bold="true"></asp:Label>
                        <%# DataBinder.Eval(Container.DataItem, "StudentName") %>
                    </td>
                    <td height="31px">
                        <asp:LinkButton ID="lnkEdit" runat="server" CommandName="edit">Edit</asp:LinkButton>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="lblAdmissionNo" runat="server" Text="AdmissionNo :" Font-Bold="true"></asp:Label>
                        <%# DataBinder.Eval(Container.DataItem, "AdmissionNo")%>
                    </td>
                </tr>

                <tr>
                    <td height="31px">
                        <asp:Label ID="lblStudentRollNo" runat="server" Text="StdentRollNo :" Font-Bold="true"></asp:Label>
                        <%# DataBinder.Eval(Container.DataItem, "StdentRollNo") %>
                    </td>
                    <td height="31px">
                        <asp:LinkButton ID="lnkEditroll" runat="server" CommandName="edit">Edit</asp:LinkButton>
                    </td>
                </tr>
         </ItemTemplate>
            <EditItemTemplate>
                <tr>
                    <td height="31px">
                        <asp:Label ID="lblStudentName" runat="server" Text="StudentName :" Font-Bold="true"></asp:Label>
                        <asp:TextBox ID="txtProductName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "StudentName") %>'></asp:TextBox>
                    </td>
                    <td>
                        <asp:LinkButton ID="lnkUpdate" runat="server" CommandName="update">Update</asp:LinkButton>
                        <asp:LinkButton ID="lnkCancel" runat="server" CommandName="cancel">Cancel</asp:LinkButton>
                    </td>
                </tr>
                <tr>
                    <td height="31px">
                        <asp:Label ID="lblAdmissionNo" runat="server" Text="AdmissionNo :" Font-Bold="true"></asp:Label>
                        <%# DataBinder.Eval(Container.DataItem, "AdmissionNo")%>
                    </td>
                </tr>

                <tr>
                    <td height="31px">
                        <asp:Label ID="lblStudentRollNo" runat="server" Text="StudentRollNo :" Font-Bold="true"></asp:Label>
                        <asp:TextBox ID="txtStudentRollNo" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "StdentRollNo") %>'></asp:TextBox>
                    </td>
                    <td>
                        <asp:LinkButton ID="LinkButton1" runat="server" CommandName="update">Update</asp:LinkButton>
                        <asp:LinkButton ID="LinkButton2" runat="server" CommandName="cancel">Cancel</asp:LinkButton>
                    </td>
                </tr>
          </EditItemTemplate>
            <FooterTemplate>
                </table>
            </FooterTemplate>
        </asp:DataList>

code behind:

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            DataTable dt = new DataTable();
            dt = obj.GetSamples();

            DataList1.DataSource = dt;
            DataList1.DataBind();
        }

    }


    public void DataBind()
    {
        DataTable dt = new DataTable();
        dt = obj.GetSamples();

        DataList1.DataSource = dt;
        DataList1.DataBind();
    }

  protected void DataList1_EditCommand1(object source, DataListCommandEventArgs e)
    { 

        DataList1.EditItemIndex = e.Item.ItemIndex;

        DataBind();


    }

  protected void DataList1_CancelCommand1(object source, DataListCommandEventArgs e)
    {

        DataList1.EditItemIndex = -1;
        DataBind();

    }



  protected void DataList1_UpdateCommand1(object source, DataListCommandEventArgs e)
    { // Get the DataKey value associated with current Item Index.
      //  int AdmissionNo = Convert.ToInt32(DataList1.DataKeys[e.Item.ItemIndex]);
        string AdmissionNo = DataList1.DataKeys[e.Item.ItemIndex].ToString();

        // Get updated value entered by user in textbox control for
        // ProductName field.
        TextBox txtProductName;
        txtProductName = (TextBox)e.Item.FindControl("txtProductName");

        TextBox txtStudentRollNo;
        txtStudentRollNo = (TextBox)e.Item.FindControl("txtStudentRollNo");

        // string variable to store the connection string
        // retrieved from the connectionStrings section of web.config
        string connectionString = ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;

        // sql connection object
        SqlConnection mySqlConnection = new SqlConnection(connectionString);

        // sql command object initialized with update command text
        SqlCommand mySqlCommand = new SqlCommand("update SchoolAdmissionForm set StudentName=@studentname ,StdentRollNo=@studentroll where AdmissionNo=@admissionno", mySqlConnection);
        mySqlCommand.Parameters.Add("@studentname", SqlDbType.VarChar).Value = txtProductName.Text;
        mySqlCommand.Parameters.Add("@admissionno", SqlDbType.VarChar).Value = AdmissionNo;
        mySqlCommand.Parameters.Add("@studentroll", SqlDbType.VarChar).Value = txtStudentRollNo.Text;


        // check the connection state and open it accordingly.
        if (mySqlConnection.State == ConnectionState.Closed)
            mySqlConnection.Open();

        // execute sql update query
        mySqlCommand.ExecuteNonQuery();

        // check the connection state and close it accordingly.
        if (mySqlConnection.State == ConnectionState.Open)
            mySqlConnection.Close();

        // reset the DataList mode back to its initial state
        DataList1.EditItemIndex = -1;
        DataBind();
        //  BindDataList();

    }

But it works fine…. but when I click edit command both the Fields

1.StudentName

2.StudentRollNo

I’m getting textboxes to all the fields where I placed textbox when I click ‘edit’ command and not the particular field alone . but I should get only the textbox visible to the field to which I click as ‘edit’ and the rest remain same without showing textboxes even though it is in editmode.

  • 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-14T00:04:08+00:00Added an answer on May 14, 2026 at 12:04 am

    When you are setting your DataList1.EditItemIndex this applies to the whole item. The item template is replaced with the edit template. This is not done on a control by control basis but on a whole item template basis.

    Your EditTemplate has multiple textboxes so the row that is in edit mode will reflect this entire template not just a single control within the template. Notice you are setting the whole DataList’s edit index and not saying set control X within the DataList.

    If you want control specific level edit templating you will need to do it manually as the DataList control was intended for editting of entire rows of data.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Also check this thread (http://drupal.org/node/438940) and the reference to John… May 14, 2026 at 4:24 am
  • Editorial Team
    Editorial Team added an answer Looking at just the code attached, one can not find… May 14, 2026 at 4:24 am
  • Editorial Team
    Editorial Team added an answer QWidget has built in support for layouts through the layout()… May 14, 2026 at 4:24 am

Related Questions

I have a datalist with itemtemplate which contains: an anchor and an href tag
I have a class that looks like this: public class Person { public string
I have a MultiView control which has a View in which a DataList is
I have a DataList control that displays a set of elements. Can anyone point
Ok I have been working on this gallery for some time and I keep

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.