开发者

How to perform delete and edit in a gridview which is dynamically added from the codebehind and which is inside a accordion control

I am in the middle of something, and i need some help. I have an accordion control and inside that i have a gridview control. And i am able to bind the values from the database to each gridview. What i want to do next is to perrform the edit and delete operations. I tried so many workarounds and everything were in vain. I am hereby attaching the aspx and code behind for your reference. Any help will be greatly appreciated.

Aspx Page

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CategoriesTransaction.ascx.cs"
    Inherits="Tools.UserControls.CategoriesTransaction" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<ajaxToolkit:Accordion ID="accCategoryDetails" runat="server" Width="100%" SuppressHeaderPostbacks="true"
    OnItemDataBound="accCategoryDetails_ItemDataBound" HeaderCssClass="headerAccordion"
    SelectedIndex="0" ContentCssClass="contentAccordion" OnInit="accCategoryDetails_Init">
    <Panes>
        <ajaxToolkit:AccordionPane ID="AccordionPane" runat="server">
            <Header>
            </Header>
            <Co开发者_StackOverflow社区ntent>
            </Content>
        </ajaxToolkit:AccordionPane>
    </Panes>
</ajaxToolkit:Accordion>

Code Behind

    private void bindGrid()
            {
                DataTable category = new DataTable();
                category = MySqlDAL.getCategoriesReconciled();

                if (category.Rows.Count != 0)
                {
                    AjaxControlToolkit.Accordion accordion = FindControl("accCategoryDetails") as AjaxControlToolkit.Accordion;
                    AjaxControlToolkit.AccordionPane pane = FindControl("AccordionPane") as AjaxControlToolkit.AccordionPane;
                    int i = 0;


                    foreach (DataRow dr in category.Rows)
                    {
                        string categoryName = dr["category"].ToString();
                        if (accordion == null)
                        { return; }


                        {
                            GridView grid = new GridView();

                            if (grid == null)
                            {
                                return;
                            }
                            else
                            {
                                DataTable transactions = new DataTable();
                                transactions = MySqlDAL.getTransactionBasedCategories(categoryName);

                                grid.DataSource = transactions;
                                grid.AutoGenerateColumns = false;
//Formatting Grid
                                FormatColumns(transactions, grid);
                                grid.AutoGenerateDeleteButton = true;

                                grid.CssClass = "Grid";
                                grid.DataBind();

                            }

                            pane = new AjaxControlToolkit.AccordionPane();
                            pane.ID = "AccordionPane" + i;
                            pane.HeaderContainer.Controls.Add(categorylbl);
                            pane.HeaderContainer.Controls.Add(budgetAmountlbl);
                            pane.HeaderContainer.Controls.Add(overUnderlbl);
                            pane.HeaderContainer.Controls.Add(tranontAvglbl);
                            pane.ContentContainer.Controls.Add(grid);
                            accCategoryDetails.Panes.Add(pane);
                            ++i;

                        }
                    }
                }
            }

What i need to do is perform edit and delete for each gridview inside the accordion. Thanks in advance


I am not to sure about this, but it appears you are using a data table not a gridview. Try adding a Gridview and binding the data table to it.

Or just adding a Gridview.

To Edit the data table though try this... let us say that your datatable ise like this

DataTable dt = new DataTable(); dt.Rows[0]["ColumnName"] = "myrow";

here [0] is the row index and [" ColumnName"] is column name, after that you asign what ever data you want to datatable.

hope this helps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜