This is a migrated thread and some comments may be shown as answers.

Accessing New Values on Client on Insert

1 Answer 53 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Elliott
Top achievements
Rank 2
Elliott asked on 26 May 2010, 09:49 PM
I am trying to hook a simple javascript function to update and insert link buttons on a radgrid
The Update is done - adding an attribute to the appropriate link button on the ItemDataBound event handler
the Insert button has me stumped
I am running VS 2010, .NET 4.0 and the code behind, as you can see, is VB
on Windows XP IE 8
anyway, appropriate code

<script type="text/javascript" language="javascript" >
    function ValidateRow(rowIndex) {
        var theGrid = $find("<%=rgDealerMaintenance.ClientID%>");
        var oneRow = null;
        if (rowIndex > -1) {
        oneRow = theGrid.get_masterTableView().get_dataItems()[rowIndex].get_element();
        }
     // hard coded cell locations
        for (j = 0; j < oneRow.cells[0].childNodes.length; j++) {
            var FirstName = oneRow.cells[0].childNodes[j].value;
        }
        for (j = 0; j < oneRow.cells[1].childNodes.length; j++) {
            var LastName = oneRow.cells[1].childNodes[j].value;
        }
        if (FirstName == '' || LastName == '') {
            alert('Please enter both a first name and a last name');
            return false;
        }
        return true;
    }
</script>
the grid
    <telerik:RadGrid ID="rgDealerMaintenance" AutoGenerateColumns="False"
        AllowAutomaticInserts="True" GridLines="None" ShowFooter="true" runat="server" >
    <MasterTableView CommandItemDisplay="Bottom" EditMode="InPlace" DataKeyNames="RegistrationID" HeaderStyle-CssClass="body_text_black_BOLD">
    <CommandItemSettings AddNewRecordImageUrl="Images/AddRecord.gif" AddNewRecordText="Add New" />
    <Columns>
        <telerik:GridBoundColumn DataField="RegistrationID" Visible="false" />
        <telerik:GridBoundColumn UniqueName="txtFirstName" DataField="FirstName" HeaderText="First Name">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn UniqueName="txtLastName" DataField="LastName" HeaderText="Last Name">
        </telerik:GridBoundColumn>

        <telerik:GridEditCommandColumn EditText="Edit" UniqueName="EditCommandColumn" UpdateText="Update" CancelText="Cancel" HeaderText="Edit">
        </telerik:GridEditCommandColumn>
        <telerik:GridButtonColumn CommandName="Delete" Text="Delete" HeaderText="Delete">
        </telerik:GridButtonColumn>
    </Columns>
    </MasterTableView>
    </telerik:RadGrid>

in the code behind
    Protected Sub rgDealerMaintenance_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgDealerMaintenance.ItemDataBound
        Dim gdItem As GridDataItem = Nothing
        Dim geItem As GridEditableItem = Nothing
        Dim btnDelete, btnUpdate As LinkButton
        Dim RowIndex As Integer
        If TypeOf e.Item Is GridDataItem Then
            gdItem = DirectCast(e.Item, GridDataItem)
            ' hard-coded location!
            btnDelete = DirectCast(gdItem.Cells(9).Controls(0), LinkButton)
            btnDelete.Attributes.Add("onclick", "return ConfirmDelete();")
        End If
        If TypeOf e.Item Is GridEditableItem And e.Item.IsInEditMode Then
            geItem = DirectCast(e.Item, GridEditableItem)
            btnUpdate = DirectCast(geItem.Cells(8).Controls(0), LinkButton)
            RowIndex = e.Item.ItemIndex
        SetLinkButtonClickEvent(btnUpdate, RowIndex)
        End If
    End Sub

    Private Sub SetLinkButtonClickEvent(ByVal btnUpdate As LinkButton, ByVal RowIndex As Integer)
        Dim sb As StringBuilder = Nothing

        If btnUpdate Is Nothing Then
            Exit Sub
        End If
        sb = New StringBuilder("return ValidateRow(")
        sb.Append(RowIndex.ToString)
        sb.Append(");")
        btnUpdate.Attributes.Add("onclick", sb.ToString)
    End Sub

how do I check for first and last name on the client in insert mode?

Marianne Seggerman




1 Answer, 1 is accepted

Sort by
0
Elliott
Top achievements
Rank 2
answered on 27 May 2010, 06:19 PM
found a solution
http://www.telerik.com/help/aspnet-ajax/grdvalidation.html

pulled out all the javascript, wired in required field validators (that is what I needed anyway)


Tags
Grid
Asked by
Elliott
Top achievements
Rank 2
Answers by
Elliott
Top achievements
Rank 2
Share this question
or