I need to set values for a DataRow for the DataTable

I need to set values for a DataRow for the DataTable that is bound from the DataSet to the grid. I am a newbie to this.
I am using visual studio 2003, vb, control from Infragistic. I know what i have to do but not sure how to implement this in my cold. I am bounded to and xml file, and I need to do this because when i add a new row, in order to input the info this has to be done.

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub
 
#End Region
 
#Region " Declarations "
 
    ' User Controls -   Menu
 
    ''Private _XmlOutput As String = Server.MapPath("Data\EggPricingOutput.xml")
    Private _XmlInput As String = Server.MapPath("Data\EggPricingTemplate.xml")
    Private _XmlPreview As String = Server.MapPath("Data\EggPricingPreview.xml")
 
#End Region
    Dim sTemp As Integer = Nothing
 
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
        If Not IsPostBack Then
            ShowFormOnScreen()
        End If
    End Sub
 
    Private Function InitFiles() As Boolean
        '
        Try
            If Not System.IO.File.Exists(_XmlPreview) Then
                System.IO.File.Copy(_XmlInput, _XmlPreview)
            End If
            Return True
        Catch ex As Exception
            Return False
        End Try
        '
    End Function
 
    Private Function CreateDataSource() As DataSet
        '
        Dim xml As New XmlDataDocument
        '
        xml.DataSet.ReadXmlSchema(_XmlPreview)
        xml.Load(_XmlPreview)
        '
        Return xml.DataSet
        '
    End Function
 
    Private Sub ShowFormOnScreen()
        '
        lblMessage.Visible = False
 
        Try
            If InitFiles() Then
 
                Dim ds As DataSet = CreateDataSource()
                '
                With UltraWebGrid1
                    .DataSource = ds.Tables(0)
                    .DataBind()
                End With
 
                txtSaleDate.Text = ds.Tables(1).Rows(0).Item(0).ToString
                txtComment.Text = ds.Tables(1).Rows(0).Item(1).ToString
            Else
                With lblMessage
                    .Visible = True
                    .CssClass = "labelRed"
                    .Text = "File can NOT be created. Please contact the A1S help desk at (914) 697-5357."
                End With
 
            End If
 
        Catch ex As Exception
 
            With lblMessage
                .Visible = True
                .CssClass = "labelRed"
                .Text = "An error occurred. Please contact the A1S help desk at (914) 697-5357."
            End With
 
        End Try
 
        '
    End Sub
    Public Sub doClearAll()
 
        Dim ds As DataSet = CreateDataSource()
        Dim row As DataRow
 
        For Each row In ds.Tables(0).Rows
            row("unit_price") = ""
            row("case_price") = ""
            row("SRP") = ""
        Next
 
        ds.WriteXml(_XmlPreview)
 
        'sTemp = 5
 
        With UltraWebGrid1
            '.EditItemIndex = -1
            .DataSource = CreateDataSource().Tables(0)
            .DataBind()
        End With
 
        txtSaleDate.Text = ""
        txtComment.Text = ""
        Me.lblMessage.Text = ""
        Me.UltraWebGrid1.DisplayLayout.SelectedRows.Clear()
        '
 
    End Sub
 
    Private Sub btnPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPreview.Click
        '
        If ConstractXML() Then
            Session("rtnPage") = "/dairy/EggInputForm.aspx"
            Response.Redirect("/dairy/Preview.aspx")
        End If
        '
    End Sub
 
    Private Function ConstractXML() As Boolean
        '
        ' Add comment and date fields to xml 
        '
        Dim ds As DataSet
        '
        Try
            ds = CreateDataSource()
 
            ds.Tables(1).Rows(0).Item(0) = txtSaleDate.Text
            ds.Tables(1).Rows(0).Item(1) = txtComment.Text
 
            ds.WriteXml(_XmlPreview)
 
            Return True
 
 
        Catch ex As Exception
            Response.Write(ex.Message)
            Response.Write("<br/><font color='red' >Error occurred.Preview file has not been created.</font>")
            Return False
 
        Finally
 
        End Try
 
        '
    End Function
    Private Sub UltraWebGrid1_InitializeLayout(ByVal sender As Object, ByVal e As Infragistics.WebUI.UltraWebGrid.LayoutEventArgs) Handles UltraWebGrid1.InitializeLayout
        UltraWebGrid1.DisplayLayout.AllowUpdateDefault = AllowUpdate.Yes
        UltraWebGrid1.DisplayLayout.AllowAddNewDefault = AllowAddNew.Yes
        UltraWebGrid1.Bands(0).Columns.FromKey("ID").Move(0)
        UltraWebGrid1.Bands(0).Columns.FromKey("pack.size").Move(1)
        UltraWebGrid1.Bands(0).Columns.FromKey("Description").Move(2)
        UltraWebGrid1.Bands(0).Columns.FromKey("unit_price").Move(3)
        UltraWebGrid1.Bands(0).Columns.FromKey("case_price").Move(4)
        UltraWebGrid1.Bands(0).Columns.FromKey("srp").Move(5)
 
        UltraWebGrid1.DisplayLayout.Bands(0).Columns(6).Hidden = True
        UltraWebGrid1.DisplayLayout.Bands(0).Columns(7).Hidden = True
        UltraWebGrid1.DisplayLayout.Bands(0).Columns(8).Hidden = True
 
        UltraWebGrid1.DisplayLayout.Bands(0).Columns(0).Header.Caption = "ID"
        UltraWebGrid1.DisplayLayout.Bands(0).Columns(1).Header.Caption = "Pack/Size"
        UltraWebGrid1.DisplayLayout.Bands(0).Columns(2).Header.Caption = "Description"
        UltraWebGrid1.DisplayLayout.Bands(0).Columns(3).Header.Caption = "Unit Price"
        UltraWebGrid1.DisplayLayout.Bands(0).Columns(4).Header.Caption = "Case Price"
        UltraWebGrid1.DisplayLayout.Bands(0).Columns(5).Header.Caption = "SRP"
 
        UltraWebGrid1.DisplayLayout.Bands(0).Columns(0).Key = "ID"
        UltraWebGrid1.DisplayLayout.Bands(0).Columns(1).Key = "pack.size"
        UltraWebGrid1.DisplayLayout.Bands(0).Columns(2).Key = "Description"
        UltraWebGrid1.DisplayLayout.Bands(0).Columns(3).Key = "unit_price"
        UltraWebGrid1.DisplayLayout.Bands(0).Columns(4).Key = "case_price"
        UltraWebGrid1.DisplayLayout.Bands(0).Columns(5).Key = "SRP"
 
        UltraWebGrid1.DisplayLayout.Bands(0).Columns(0).Width = Unit.Pixel(100)
        UltraWebGrid1.DisplayLayout.Bands(0).Columns(1).Width = Unit.Pixel(100)
        UltraWebGrid1.DisplayLayout.Bands(0).Columns(2).Width = Unit.Pixel(430)
        UltraWebGrid1.DisplayLayout.Bands(0).Columns(3).Width = Unit.Pixel(100)
        UltraWebGrid1.DisplayLayout.Bands(0).Columns(4).Width = Unit.Pixel(100)
        UltraWebGrid1.DisplayLayout.Bands(0).Columns(5).Width = Unit.Pixel(100)
 
        ' set the DataKeyField so when the events are thrown the
        ' row.datakey property can be populated
 
        e.Layout.Bands(0).DataKeyField = "GUID"
        ' turn on edit, update, delete and show the AddNewBox
        e.Layout.AllowAddNewDefault = Infragistics.WebUI.UltraWebGrid.AllowAddNew.Yes
        e.Layout.AllowDeleteDefault = Infragistics.WebUI.UltraWebGrid.AllowDelete.Yes
        e.Layout.AllowUpdateDefault = Infragistics.WebUI.UltraWebGrid.AllowUpdate.Yes
        UltraWebGrid1.DisplayLayout.AddNewBox.Style.BackColor = Color.BlanchedAlmond
        e.Layout.AddNewBox.Hidden = False
        ' set the default cell click action to edit
        e.Layout.CellClickActionDefault = _
        Infragistics.WebUI.UltraWebGrid.CellClickAction.Edit
        e.Layout.CellClickActionDefault = _
        Infragistics.WebUI.UltraWebGrid.CellClickAction.CellSelect
        ' add a hidden GUID column to band(0)
        With e.Layout.Bands(0)
            Dim objTable As DataTable = New DataTable
            Dim objRow As DataRow
            .Columns.Add("GUID")
           
            .Columns.FromKey("GUID").Hidden = True
 
           
 
            ' .Rows.Add(objRow)
            '   Next i
        End With
 
    End Sub
 
 
  
 
 
    Private Sub UltraWebGrid1_UpdateRow(ByVal sender As Object, ByVal e As Infragistics.WebUI.UltraWebGrid.RowEventArgs) Handles UltraWebGrid1.UpdateRow
 
        Dim oldRow As UltraGridRow = CType(e.Data, UltraGridRow)
 
        Dim dataKey As String = CStr(e.Row.DataKey)
 
        'newer fields
        'Dim ID As String = e.Row.Cells(0).Value
        'Dim PackSize As String = e.Row.Cells(1).Value
        'Dim Description As String = e.Row.Cells(2).Value
        'Dim Description As String = e.Row.Cells(2).Value
 
 
        Dim sUnitPrice As String = e.Row.Cells(3).Value
        Dim sSRP As String = e.Row.Cells(5).Value
        Dim CasePrice As Decimal
        'Dim sCasePrice As String = e.Row.Cells(4).Value
 
        If Not IsNumeric(sUnitPrice) Then
            With lblMessage
                .Visible = True
                .CssClass = "labelRed"
                .Text = "Last Price field must be numeric! Your data is not saved. Please reenter your Last Price."
            End With
            Exit Sub
        ElseIf Not IsNumeric(sSRP) Then
            With lblMessage
                .Visible = True
                .CssClass = "labelRed"
                .Text = "Current Price field must be numeric! Your data is not saved. Please reenter your Current Price."
            End With
            Exit Sub
        End If
 
        Dim ds As DataSet = CreateDataSource()
        Dim row As DataRow = ds.Tables(0).Rows(e.Row.Index)
 
 
        If IsNumeric(sUnitPrice) Then
            CasePrice = Convert.ToDecimal(e.Row.Cells(7).Value) * Convert.ToDecimal(sUnitPrice)
            row("case_price") = System.Decimal.Round(CasePrice, 2)
        End If
 
        row("SRP") = sSRP
 
        ds.WriteXml(_XmlPreview)
 
        Me.UltraWebGrid1.DisplayLayout.SelectedRows.Clear()
 
        With UltraWebGrid1
            '.EditItemIndex = -1
            .DataSource = CreateDataSource().Tables(0)
            .DataBind()
        End With
 
        With lblMessage
            .Visible = True
            .CssClass = "labelGreen"
            .Text = "Your data was succesfully modified and saved."
        End With
    End Sub
 
    
 
 
 
    Private Sub UltraWebGrid1_UpdateGrid(ByVal sender As Object, ByVal e As Infragistics.WebUI.UltraWebGrid.UpdateEventArgs) Handles UltraWebGrid1.UpdateGrid
        Dim table As DataTable
        Dim row As UltraGridRow
       
 
 
    End Sub
    Private Sub BtnClearAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClearAll.Click
        Call doClearAll()
    End Sub
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 
 
        '
 
 
        Dim ds As DataSet = CreateDataSource()
        Dim row As DataRow
 
        For Each row In ds.Tables(0).NewRow
            row("unit_price") = ""
            row("case_price") = ""
            row("SRP") = ""
        Next
 
        ds.WriteXml(_XmlPreview)
 
 
 
        ds.Tables(1).Rows(0).Item(0) = txtSaleDate.Text
        ds.Tables(1).Rows(0).Item(1) = txtComment.Text
        ds.WriteXml(_XmlPreview)
 
        ds.WriteXmlSchema("EggPricingPreview.xml")
        If ds.Tables.Count = 0 Then
            With lblMessage
                .Visible = True
                .CssClass = "labelRed"
                .Text = " There is no file located Please add a file to create your data"
            End With
            Exit Sub
 
 
        End If
 
 
    End Sub

Open in new window

LVL 9
Seven priceFull StackAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Syed Irtaza AliLead Software ArchitectCommented:
Not sure what exactly you want, I am just taking a guess that you want to be able to add a new row that displays in the grid as well. If that is the case, rather than binding a DataTable to the UltraWebGrid try binding a DataView.
 
//Try something like this... I have written the C# syntax
private DataView dvGridRows; //declare this in #Region " Declarations "
...
...
dvGridRows = ds.Tables[0].DefaultView;
With UltraWebGrid1
    .DataSource = dvGridRows;
    .DataBind()
End With
...
...
private void CreateNewRow(){
   DataRow drNew = ds.Tables[0].NewRow();
   drNew["ColumnName1"] = "Value1";
   ds.Tables[0].Rows.Add(drNew);
   //refresh the UltraWebgrid here to display the new row
}

Open in new window

0
Seven priceFull StackAuthor Commented:
I need to do somthing like this but i can i change this for xml, since i am a newbie at this. can you modify this to match what i need then i could have a better understanding.
private void InsertRecord(UltraGridRow theGridRow)
{
    CategoriesRow theCategory;
    theCategory = NorthwindDataSet.Categories.NewCategoriesRow();
    theCategory.CategoryName = theGridRow.Cells.FromKey(CategoryName).Value.ToString();
    theCategory.Description = theGridRow.Cells.FromKey(Description).Value.ToString();
    NorthwindDataSet.Categories.Rows.Add(theCategory);
    this.SqlDataAdapterCategories.Update(NorthwindDataSet.Categories);
    theGridRow.Cells.FromKey(CategoryID).Value = theCategory.CategoryID;
}
 
In VB.NET:
Private Sub InsertRecord(theGridRow As UltraGridRow)
    Dim theCategory As CategoriesRow
    theCategory = NorthwindDataSet.Categories.NewCategoriesRow( )
    theCategory.CategoryName = theGridRow.Cells.FromKey(CategoryName).Value.ToString( )
    theCategory.Description = theGridRow.Cells.FromKey(Description).Value.ToString( )
    NorthwindDataSet.Categories.Rows.Add(theCategory)
    Me.SqlDataAdapterCategories.Update(NorthwindDataSet.Categories)
    theGridRow.Cells.FromKey(CategoryID).Value = theCategory.CategoryID
End Sub

Open in new window

0
Syed Irtaza AliLead Software ArchitectCommented:
Im now a bit confused with the above code.
When you add/insert a new row in the DataSet you can save the dataset after that and refresh the UltraWebGrid.

I dont have Infragistics so cant send you the exact code for retrieving values from the row cells.

private void CreateNewRow(){
   DataRow drNew = ds.Tables[0].NewRow();
   drNew["CategoryName"] = "Value1"; //the value you want to save
   drNew["Description"] = "Value2"; //the value you want to save
   ds.Tables[0].Rows.Add(drNew);
   //Save your DataSet in XML here like ds.WriteXML()
   //refresh the UltraWebgrid here to display the new row
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Seven priceFull StackAuthor Commented:
adding to xml dataset
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.