Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
260
Add rows below one Particular row on Button click in Webdatagrid.
posted

Hi Nikolay,

I want to add new rows in webdatagrid below one particular row on button click using javascript.

If data exists in that row were we adding a new row then that data should move to next row but we are facing the issue like data exist in that new row.

Moreover we are using template data field and not bound data field .

pls help me out this.

 

our code :

Design Page:

Button is in Toolbar:Click on button should add row in the grid

we tried adding row only at the bottom of the grid.But we need to add it below one particular row.For this want can we do how to get that particular row id / value and get add rows below that row using javascript? 

Similarly while continues click of add button display multiple rows..

 

 

 

 

 

 

<td>

 

 

 

<asp:Button ID="btnAdd" runat="server" Text="Add Event" OnClickclient="return AddEvent();"></asp:Button></td>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

<ig:WebDataGrid ID="dgMainPlan" runat="server" AutoGenerateColumns="False" ItemCssClass="VerticalLines"HeaderCaptionCssClass="Header" OnInitializeRow="dgMainPlanInitializeRow">

 

 

 

 

<Columns>

 

 

 

<ig:TemplateDataField Key="ID" Width="2%">

 

 

 

<ItemTemplate>

<%

 

#DataBinder.Eval(((Infragistics.Web.UI.TemplateContainer)Container).DataItem, "ID")%>

 

 

 

</ItemTemplate>

 

 

 

</ig:TemplateDataField>

 

 

 

<ig:TemplateDataField Key="EWA" Width="4%">

 

 

 

<ItemTemplate><%#DataBinder.Eval(((Infragistics.Web.UI.TemplateContainer)Container).DataItem, "EWA")%>

 

 

 

</ItemTemplate>

 

 

 

</ig:TemplateDataField>

 

 

 

<ig:TemplateDataField Key="TestItem" Width="6%"><ItemTemplate>

<%#DataBinder.Eval(((Infragistics.Web.UI.TemplateContainer)Container).DataItem, "TestItem")%>

 

 

 

</ItemTemplate>

 

 

 

</ig:TemplateDataField>

 

 

 

<ig:TemplateDataField Key="Title" Width="4%">

 

 

 

<ItemTemplate>

<%

 

 

#DataBinder.Eval(((Infragistics.Web.UI.TemplateContainer)Container).DataItem, "Title")%>

 

 

 

</ItemTemplate>

 

 

 

</ig:TemplateDataField>

 

 

 

<ig:TemplateDataField Key="EPTD" Width="9%">

 

 

 

<ItemTemplate>

<%

 

#DataBinder.Eval(((Infragistics.Web.UI.TemplateContainer)Container).DataItem, "EPTD")%>

 

 

 

</ItemTemplate>

 

 

 

</ig:TemplateDataField>

 

 

 

<ig:TemplateDataField Key="Req" Width

="15%">

 

 

 

<ItemTemplate>

<%

 

#DataBinder.Eval(((Infragistics.Web.UI.TemplateContainer)Container).DataItem, "Req")%>

 

 

 

</ItemTemplate>

 

 

 

</ig:TemplateDataField>

 

 

 

</Columns>

 

 

 

<Behaviors>

 

 

 

<ig:EditingCore>

 

 

 

<Behaviors>

 

 

 

<ig:RowAdding>

 

 

 

</ig:RowAdding>

 

 

 

</Behaviors>

 

 

 

</ig:EditingCore>

 

 

 

</Behaviors>

 

 

 

</ig:WebDataGrid>

 In cs file

 

 

 

 

 

 

 

 

 

 

protected void Page_Load(object sender, EventArgs

e)

{

 

 

 

DataSet dsPlanData = new DataSet

();

CreateDataSet();

 

 

 

if

(!IsPostBack)

{

 

 

 

//CreateDataSet();

SetToolBar();

dsPlanData = GetTWSSheetData();

SetGridColumns(dsPlanData);

 

 

//generate columns at runtime based on start date and end date with the headers

DisplayTWSSheetData(dsPlanData);

 

 

//Method to bind the dropdown data (TD,Ground Ops,Module and Block)

}

 In PAGE LOAD we are calling the CreateDataSet() method were we creating the datatable with columns and rows which is fixed in the grid and binding to grid.

on button click we need to add row below this particular datarow.

GetTWSSheetData()-used to get data from database.

SetGridColumns()-used to create template columns and rows at runtime and bind to grid.

DisplayTWSSheetData()-display the data in grid.

We tried adding row in Code behind with adding ner row to datatable and insert row at particular location.but we face issues..

on continues click it is not generating rows....

Major Issue:

1.Since postback occurs on button click every data in the grid get disappears and not able to edit the data in the grid.

2.Multiple clicks on the Add button is generating only one row because the page post back happens, which will fetch the old data from the database and add a new row again after the particular(EQA/Title)row in the grid. .

3.pls help me out using javascript for above issue...

Can u share ur Mobile no Nikolay to discuss this issue if required.....it is urgent or else we can book a webex seesion when u are free...

since we bought licensed version and using Nedadvantage V11.1......and we working in webdatagrid.

sorry for long content.....

Thanks & Regards

Vijayan

 

Parents
No Data
Reply
  • 37874
    posted

    Hi Vijayan,

     

    Since I don’t see appropriate method to add rows at specified index client-side, I would suggest that you do this in your code-behind. In case you are using DataTable as data source for your WebDataGrid, the binding and RowAdding handler could look something like the following:

     

        protected void Page_Load(object sender, EventArgs e)

        {

            if (!IsPostBack)

            {

                //GetDataSource() returns DataTable, used for data source for the grid

                Session["DS"] = GetDataSource();

            }

            WebDataGrid1.DataSource = (DataTable)Session["DS"];

        }

     

        protected void WebDataGrid1_RowAdding(object sender, Infragistics.Web.UI.GridControls.RowAddingEventArgs e)

        {

            DataTable dt = (DataTable)Session["DS"];

            Session["DS"] = dt;

            DataRow row = dt.NewRow();

            //Gets the values to insert into the new row, for example, if you have columns ID, FirstName and LastName:

            row.ItemArray = new object[] { e.Values["ID"], e.Values["FirstName"], e.Values["LastName"] };

            //Inserts new row at the specified index

            dt.Rows.InsertAt(row, 5);

            WebDataGrid1.DataSource = (DataTable)Session["DS"];

            WebDataGrid1.DataBind();

        }

     

    Please let me know if this helps.

Children