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

  • Home
  • SEARCH
  • 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 8762697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:35:48+00:00 2026-06-13T15:35:48+00:00

i have a repeater control which contains grids, based on values from database, say

  • 0

i have a repeater control which contains grids, based on values from database, say for example i have 2 grids inside repeater control, now both the grids contains a column which have up and down buttons, now when user clicks on the button from any grids, how can i check from which grid the button is called.
below is my code where i am filling the grids on RepeaterItemDataBound Event

GridView gvw = e.Item.FindControl("grid") as GridView;
gvw.DataSource = info.GetStories(sectionNames[e.Item.ItemIndex].Trim());
gvw.DataBind();

here section name contains the name of the sections, based on number of sections, i generate the grids.
My Design looks like this:

<asp:Repeater ID="rptGrids" runat="server" 
                        OnItemDataBound="rptGrids_ItemDataBound">
                        <ItemTemplate>
                            <asp:GridView ID="grid" runat="server" Width="100%" CellPadding="5" AllowPaging="true" ShowHeader="true" PageSize="10" AutoGenerateColumns="false" OnRowCommand="Stories_RowCommand">
                                <Columns>
                                    <asp:BoundField DataField="ArticleID" HeaderText="Article ID" ItemStyle-CssClass="center" />
                                    <asp:BoundField DataField="CategoryID" HeaderText="Category ID" ItemStyle-CssClass="center" />
                                    <asp:BoundField DataField="Title" HeaderText = "Article Title" />
                                    <asp:BoundField DataField="PublishDate" DataFormatString="{0:d}" HeaderText="Publish Date" ItemStyle-CssClass="center" />
                                    <asp:TemplateField HeaderText="Select Action" ItemStyle-CssClass="center">
                                        <ItemTemplate>
                                            <asp:ImageButton ID="btnMoveUp" runat="server" ImageUrl="/images/up.gif" CommandArgument="Up" CommandName='<%# Container.DataItemIndex + "," + DataBinder.Eval(Container.DataItem, "StoryType") %>' />
                                            <asp:ImageButton ID="btnMoveDown" runat="server" ImageUrl="/images/dn.gif" CommandArgument="Down" CommandName='<%# Container.DataItemIndex + "," + DataBinder.Eval(Container.DataItem, "StoryType") %>' />
                                            <asp:ImageButton ID="btnDelete" runat="server" ImageUrl="/images/deny.gif" CommandArgument="Delete" OnClientClick="return confirm('Are you sure you want to delete this article?');" CommandName='<%# Container.DataItemIndex %>' />
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField Visible="false">
                                        <ItemTemplate>
                                            <asp:HiddenField ID="hdStoriesSortOrder" runat="server" Value='<%# Eval("SortOrder") %>' />
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                </Columns>
                            </asp:GridView>
                            <div class="blank"></div>
                        </ItemTemplate>
                    </asp:Repeater>

this is my gridviews row_command event

protected void Stories_RowCommand(object sender, GridViewCommandEventArgs e)
{
    int index = Convert.ToInt32(e.CommandName.Split(',')[0]);
    string section = e.CommandName.Split(',')[1].Trim().ToString();
    string command = e.CommandArgument.ToString();
    if (command.ToLower() == "up")
    {
        GridView grd = rptGrids.Items[1].FindControl("grid") as GridView; // If i specify the index here, i gets proper grid, but how to recognize at runtime.
        Response.Write(grd.Rows.Count);
    }
    else if (command.ToLower() == "down")
    {

    }
}

can anyone tell me how can i get from which grid up/down button has been clicked.

  • 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-06-13T15:35:50+00:00Added an answer on June 13, 2026 at 3:35 pm

    You can use command argument to pass required value.
    Here is sample of using imagebutton in similar way:

                    <asp:ImageButton ID="btnView" runat="server" ToolTip="<% $resources:AppResource,Edit %>"
                        SkinID="EditPage" CommandName="myCommand" CommandArgument='<%# Eval("CustomerId") %>'
                        PostBackUrl='<%# "~/AdminPages/Customer.aspx?id=" + Eval("CustomerId").ToString() %>' />
    

    Take notice on CommandArgument property.You can set it with value that indicates specific gridview inside repeater.

    And here is how to check the value:

        protected void EntityGridViewContacts_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            //here you can check for command name...
            switch (e.CommandName)
            {
                case "myCommand":
                    //here you access command argument...
                    int customerId = Convert.ToInt32(e.CommandArgument.ToString());
                    break;
            }
    
            //here is how you access source gridview...
            GridView gridView = (GridView)sender;
            string controlId = gridView.ID;
        }
    

    You can also set CommandArgument using this approach:

    CommandArgument='<%# GetMySpecialValue() %>'
    

    Then you should declare function on page side something like this:

    public string GetMySpecialValue() 
    {
         return "some value";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a repeater control in which i am showing values from database and
Inside my Content page I have a repeater control, which contains multiple controls along
I have a Repeater control which contains a CheckBox and a lable control in
I have a custom control which contains a Repeater control. The Repeater has an
If I have a custom user control (say, MyCustomControl.ascx) which contains a number of
I have a user control in which I have Repeater control and inside this
I have a view in which I there is a repeater control wrapped with
I have a repeater control that contains an ItemTemplate containing a databound label and
I have a repeater control outputting some HTML. I want a table which outputs
I have an XML DataSource which feeds a repeater control. However, I'm having some

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.