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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:54:45+00:00 2026-05-26T13:54:45+00:00

Page Load: protected void Page_Load(object sender, EventArgs e) { tb.Columns.Add(Id, typeof(int)); tb.Columns.Add(FileName, typeof(string)); tb.Columns.Add(FilePath,

  • 0

Page Load:

 protected void Page_Load(object sender, EventArgs e)
  {

       tb.Columns.Add("Id", typeof(int));
        tb.Columns.Add("FileName", typeof(string));
        tb.Columns.Add("FilePath", typeof(string));
        tb.Columns.Add("Index", typeof(int));

        newtb.Columns.Add("Id", typeof(int));
        newtb.Columns.Add("FileName", typeof(string));
        newtb.Columns.Add("FilePath", typeof(string));
        newtb.Columns.Add("Index", typeof(int));

        path = objGetBaseCase.GetAllImagesfromGroup(CaseId);
        for (int i = 0; i < path.Count; i++)
        {
            ArrayList alst = path[i];
            tb.Rows.Add(Convert.ToInt32(alst[0]), alst[1].ToString(), alst[2].ToString(), i);

        }
        msgError.Text = "";

        dlstImage.DataSource = tb;
        DataBind();
        List<ArrayList> t = new List<ArrayList>();
        if (newpath.Count > 0)
        {
            t = newpath;
            newpath = t;
            for (int i = 0; i < newpath.Count; i++)
            {
                ArrayList alst = newpath[i];
                newtb.Rows.Add(Convert.ToInt32(alst[0]), alst[1].ToString(), alst[2].ToString(), i);

            }
            ViewState["tempimage"] = newpath;
            dlstSelectedImages.DataSource = newtb;
            DataBind();
        }

}

Datalist SelectedIndexChanged:

  protected void dlstSelectedImages_SelectedIndexChanged(object sender, EventArgs e)
  {
    indexId = Convert.ToInt32(dlstSelectedImages.DataKeys[dlstSelectedImages.SelectedIndex]);
  }

DataList:

 <asp:DataList ID="dlstSelectedImages" runat="server" RepeatDirection="Horizontal"
                                RepeatColumns="5" CellSpacing="8" DataKeyField="Id"  OnSelectedIndexChanged="dlstSelectedImages_SelectedIndexChanged">
         <ItemTemplate>
               <asp:ImageButton ID="Image"  runat="server" ImageUrl='<%#"~/Controls/ShowImage.ashx?FileName=" +DataBinder.Eval(Container.DataItem, "FilePath") %>'
                                        CommandName="Select" OnCommand="ImageSelect_Command" CommandArgument='<%# Eval("Id").ToString() +";"+Eval("FilePath")+";"+Eval("Index")+";"+Eval("FileName") %>' /><br />
                   <asp:Label ID="nlbl" runat="server" Text="Figure"></asp:Label><%# dlstSelectedImages.Items.Count + 1%>
          </ItemTemplate>
  </asp:DataList>

Itried with: View State="Enable", AutoEventWireup="true",

autopostback="true"

It was working well when i was binding the datalist inside this !IsPostBack but now I don’t want to bind my datalist inside the !IsPostBack and I don’t want to use ItemCommand as well

But its not working, someone help me…

  • 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-26T13:54:45+00:00Added an answer on May 26, 2026 at 1:54 pm

    Whenever the SelectedIndex Change event fires, the Page_Load event is called before the selectedIndex Change event. In your page_load event, your DataList binded again and hence your SelectedIndex event was lost. You have to put your DataList binding code under !IsPostBack e.g.

    protected void Page_Load(object sender, EventArgs e)
    {
      if(!IsPostBack)
      {
       newtb.Columns.Add("Id", typeof(int));
       newtb.Columns.Add("FileName", typeof(string));
       newtb.Columns.Add("FilePath", typeof(string));
       newtb.Columns.Add("Index", typeof(int));
    
       List<ArrayList> t = new List<ArrayList>();
        if (newpath.Count > 0)
        {
            t = newpath;
            newpath = t;
            for (int i = 0; i < newpath.Count; i++)
            {
                ArrayList alst = newpath[i];
                newtb.Rows.Add(Convert.ToInt32(alst[0]), alst[1].ToString(), alst[2].ToString(), i);
    
            }
            ViewState["tempimage"] = newpath;
            dlstSelectedImages.DataSource = newtb;
            DataBind();
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Then: protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { CheckBoxList1.Items.Add(new ListItem(item1)); CheckBoxList1.Items.Add(new
this is the simple code: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack)
Shouldn't PostBack be checked before Session protected void Page_Load(object sender, EventArgs e) { if
JLAdjustmentList.aspx.cs protected void Page_Load(object sender, EventArgs e) { LoadApprovalList(); } protected override void OnPreRender(EventArgs
Im setting the the datasource with the following code: protected void Page_Load(object sender, EventArgs
On PostBack, from clicking on an ImageButton, it first hits protected void Page_Load(object sender,
Consider the following code: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Please take a look at this: protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { int
In a team environment, if I handle an exception (like so): protected void Page_Load(object
Is Page.Load the earliest point in the Page.Load life cycle to add Response.AppendHeader?

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.