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
60
Requesting Example code Update UltraWebGrid via Code
posted

First, I am using v.8.3 and coding in C#.

I am trying to get a simple grid bound to a SQLDataSource to update using only (as much as is possible) C# code in the .cs file.

I would like to be able to define my Parameters for the update query of the SQLDatasource, bind it to the grid and have it update with UpdateRowBatch (on a per row basis).

I have searched far and wide for example code of setting the parameters via C# code, but have only found examples using the gui wizard to create the CRUD when defining the SQLDataSource.

The data displays fine, but does not update. Any help is greatly appreciated.

Here is the code I am trying to use. Please let me know if I need to provide any additional information.

I have tried to minimize the code, but there still may be some extra stuff in there.

 .aspx code:

    <form id="form1" runat="server">

    <div>

        <igtbl:UltraWebGrid ID="wgData" runat="server" DisplayLayout-AutoGenerateColumns="true"

            DataSourceID="mySqlDS"

            DataKeyField="myTestID"

            DataMember="DefaultView"

            Height="300px" Width="525px"

            OnInitializeLayout="wgData_InitializeLayout"

            OnInitializeRow="wgData_InitializeRow"

            OnUpdateRowBatch="wgData_UpdateRowBatch">

            <DisplayLayout AllowSortingDefault="Yes" BorderCollapseDefault="Separate" HeaderClickActionDefault="SortMulti" Name="wgData" RowHeightDefault="40px" Version="4.00">

                <FrameStyle Height="300px" Width="525px"></FrameStyle>

                <AddNewBox Hidden="False"></AddNewBox>

            </DisplayLayout>

           

        </igtbl:UltraWebGrid>

    </div>

    <asp:SqlDataSource ID="mySqlDS" runat="server" ConnectionString="<%$ ConnectionStrings:myConnectionString %>"></asp:SqlDataSource>

    <asp:Button ID="btnSave" runat="server" CausesValidation="False" Text="Save" />

    </form>

 

 and the .cs code:

 

public partial class myTestForm : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

 

        if (!this.IsPostBack)

        {

            this.wgData.DataBind();

        }

 

        wgData.DataSourceID = mySqlDS.UniqueID;

        wgData.Bands[0].DataKeyField = "myTestID";

 

        mySqlDS.OldValuesParameterFormatString = "original_{0}";

        Parameter original_myTestID = new Parameter("original_myTestID", TypeCode.Int32);

        Parameter myTestID = new Parameter("myTestID", TypeCode.Int32);

        Parameter myTestCheckFlag = new Parameter("myTestCheckFlag", TypeCode.Boolean);

        Parameter myTestCode = new Parameter("myTestCode", TypeCode.String);

        Parameter myTestDesc = new Parameter("myTestDesc", TypeCode.String);

 

        mySqlDS.UpdateParameters.Add(original_myTestID);

        mySqlDS.UpdateParameters.Add(myTestCheckFlag);

        mySqlDS.UpdateParameters.Add(myTestCode);

        mySqlDS.UpdateParameters.Add(myTestDesc);

 

        mySqlDS.InsertParameters.Add(myTestID);

        mySqlDS.InsertParameters.Add(myTestCode);

        mySqlDS.InsertParameters.Add(myTestDesc);

        mySqlDS.InsertParameters.Add(myTestCheckFlag);

 

        mySqlDS.SelectCommand = "SELECT * FROM [myTestTable]";

        mySqlDS.UpdateCommand = "UPDATE [myTestTable] SET [myTestDesc] = @myTestDesc, [myTestCode] = @myTestCode, [myTestCheckFlag] = @myTestCheckFlag WHERE [myTestID] = @original_myTestID";

 

    }

 

    protected void wgData_InitializeLayout(object sender, Infragistics.WebUI.UltraWebGrid.LayoutEventArgs e)

    {

        e.Layout.AllowUpdateDefault = Infragistics.WebUI.UltraWebGrid.AllowUpdate.Yes;

        e.Layout.AllowAddNewDefault = Infragistics.WebUI.UltraWebGrid.AllowAddNew.Yes;

        e.Layout.AddNewRowDefault.Visible = Infragistics.WebUI.UltraWebGrid.AddNewRowVisible.Yes;

       

        e.Layout.Bands[0].Columns.FromKey("myTestID").BaseColumnName = "myTestID";

        e.Layout.Bands[0].Columns.FromKey("myTestDesc").BaseColumnName = "myTestDesc";

        e.Layout.Bands[0].Columns.FromKey("myTestCode").BaseColumnName = "myTestCode";

        e.Layout.Bands[0].Columns.FromKey("myTestCheckFlag").BaseColumnName = "myTestCheckFlag";

       

        e.Layout.Bands[0].Columns.FromKey("myTestID").Key = "myTestID";

        e.Layout.Bands[0].Columns.FromKey("myTestDesc").Key = "myTestDesc";

        e.Layout.Bands[0].Columns.FromKey("myTestCode").Key = "myTestCode";

        e.Layout.Bands[0].Columns.FromKey("myTestCheckFlag").Key = "myTestCheckFlag";

 

        e.Layout.Bands[0].Columns.FromKey("myTestID").DataType = "System.Int32";

        e.Layout.Bands[0].Columns.FromKey("myTestDesc").DataType = "System.String";

        e.Layout.Bands[0].Columns.FromKey("myTestCode").DataType = "System.String";

        e.Layout.Bands[0].Columns.FromKey("myTestCheckFlag").DataType = "System.Boolean";

 

       

    }

    protected void wgData_InitializeRow(object sender, Infragistics.WebUI.UltraWebGrid.RowEventArgs e)

    {

 

    }

 

    protected void wgData_UpdateRowBatch(object sender, Infragistics.WebUI.UltraWebGrid.RowEventArgs e)

    {

 

    }

 

 Thank you.