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

RadGrid Insert Command

9 Answers 1293 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 18 Sep 2012, 09:30 AM
Hi,


I am very new to asp.net and telerik so I apologize. I need help and I am not sure how to get this accomplished. Here is what I got. I have two radgrids one is being controlled by the other. the first grid will display a list of patients a therapist has on their case load. the second grid will display a list of visits each patient has. so the visits grid is be controlled by the selected value of the patient grid by PaitentID. Ok here is my problem when I add a visit for a patient I don't know how to automatically populate the patientID for the visit from the selected value on the patient grid. So I am not sure how to go about this so any help would be greatly appreciated. thanks

9 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 18 Sep 2012, 10:04 AM
Hello,

RadGrid2 : therapist grid
RadGrid3 : patient grid

<telerik:RadGrid ID="RadGrid2" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid2_NeedDataSource"
           OnItemCommand="RadGrid2_ItemCommand">
           <MasterTableView DataKeyNames="ID">
               <Columns>
                   <telerik:GridBoundColumn HeaderText="Name" DataField="Name" UniqueName="Name">
                   </telerik:GridBoundColumn>
               </Columns>
           </MasterTableView>
           <ClientSettings EnablePostBackOnRowClick="true">
               <Selecting AllowRowSelect="true" />
           </ClientSettings>
       </telerik:RadGrid>
       <telerik:RadGrid ID="RadGrid3" runat="server" AutoGenerateColumns="false">
           <MasterTableView>
               <Columns>
                   <telerik:GridBoundColumn HeaderText="ID" DataField="ID" UniqueName="ID">
                   </telerik:GridBoundColumn>
                   <telerik:GridBoundColumn HeaderText="Name" DataField="Name" UniqueName="Name">
                   </telerik:GridBoundColumn>
               </Columns>
           </MasterTableView>
       </telerik:RadGrid>
protected void RadGrid2_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
   {
// Bind your therapist
       dynamic data = new[] {
               new { ID = 1, Name ="Name1"},
               new { ID = 2, Name = "Name2"},
               new { ID = 3, Name = "Name3"}
           };
  
  
       RadGrid2.DataSource = data;
   }
  
   protected void RadGrid2_ItemCommand(object sender, GridCommandEventArgs e)
   {// bind patient
       if (e.CommandName == "RowClick")
       {
           GridDataItem item = e.Item as GridDataItem;
           string strID = item.GetDataKeyValue("ID").ToString();
           string strName = item["Name"].Text;
  
           dynamic data = new[] {
               new { ID = strID, Name ="Name_1"},
               new { ID = strID, Name = "Name_2"},
               new { ID = strID, Name = "Name_3"},
               new { ID = strID, Name = "Name_4"},
               new { ID = strID, Name = "Name_5"}
           };
           RadGrid3.DataSource = data;
           RadGrid3.DataBind();
       }
   }


Thanks,
Jayesh Goyani
0
Shinu
Top achievements
Rank 2
answered on 18 Sep 2012, 10:39 AM
Hi Alex,

I guess you are binding the second RadGrid depending upon a value of the selected row of the first Radgrid. I have created a sample code snippet according to your requirement.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="true" PageSize="5" DataSourceID="SqlDataSource1">
        <ClientSettings EnablePostBackOnRowClick="true">
            <Selecting AllowRowSelect="true" />
        </ClientSettings>
        <MasterTableView DataKeyNames="CustomerID" />
        <PagerStyle Mode="NextPrevAndNumeric" />
</telerik:RadGrid>
 
<telerik:RadGrid ID="RadGrid2"  runat="server" DataSourceID="SqlDataSource2" AutoGenerateEditColumn="true" oninsertcommand="RadGrid2_InsertCommand">
        <MasterTableView AutoGenerateColumns="False" DataKeyNames="OrderID" DataSourceID="SqlDataSource2" CommandItemDisplay="Top">
            <Columns>
                <telerik:GridBoundColumn DataField="OrderID" DataType="System.Int32" HeaderText="OrderID"
                    ReadOnly="True" SortExpression="OrderID" UniqueName="OrderID">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="ShipCountry" HeaderText="ShipCountry" SortExpression="ShipCountry"
                    UniqueName="ShipCountry">
                </telerik:GridBoundColumn>
            </Columns>
        </MasterTableView>
        <ClientSettings EnablePostBackOnRowClick="true">
            <Selecting AllowRowSelect="true" />
        </ClientSettings>
</telerik:RadGrid>
<asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString3 %>"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, PostalCode FROM Customers" runat="server"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString3%>"
        ProviderName="System.Data.SqlClient" SelectCommand="SELECT [OrderID], [OrderDate], [CustomerID], [ShipCountry] FROM [Orders] WHERE  ([CustomerID] = @CustomerID)"
        runat="server">
  <SelectParameters>
     <asp:ControlParameter ControlID="RadGrid1" DefaultValue="ALFKI" Name="CustomerID"
      PropertyName="SelectedValue" Type="String" />
  </SelectParameters>
</asp:SqlDataSource>

C#:
protected void RadGrid2_InsertCommand(object sender, GridCommandEventArgs e)
{
    foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
    {
        if (item.Selected)
        {
            string strKey = item.GetDataKeyValue("CustomerID").ToString(); // taking the DatakeyValue of the selected row(parent RadGrid)
        }
    }
    GridEditableItem editItem = (GridEditableItem)e.Item;
    //your code for insertion
}

Thanks,
Shinu.
0
Alex
Top achievements
Rank 1
answered on 18 Sep 2012, 07:28 PM
Thank you both for you quick response but I forgot to say I am using VB is there any way you can give it to me in VB instead of C# thanks
0
Shinu
Top achievements
Rank 2
answered on 19 Sep 2012, 03:10 AM
Hi,

Here is the code in VB.

VB:
Protected Sub RadGrid2_InsertCommand(sender As Object, e As GridCommandEventArgs)
    For Each item As GridDataItem In RadGrid1.MasterTableView.Items
        If item.Selected Then
                ' taking the DatakeyValue of the selected row(parent RadGrid)
            Dim strKey As String = item.GetDataKeyValue("CustomerID").ToString()
        End If
    Next
    Dim editItem As GridEditableItem = DirectCast(e.Item, GridEditableItem)
    'your code for insertion
End Sub

Thanks,
Shinu.
0
Alex
Top achievements
Rank 1
answered on 19 Sep 2012, 04:10 AM

thanks so much but I still can't get it to work sorry maybe I explained it wrong again I am not very good at this so I apologize.

I will post my code and a pic of what I am trying to do. What I really need is when I insert on grid2 I need it automatically insert the patient ID from grid1. and Ill I have to do is type in units and the date.SO maybe like a onclick event or something. so when I click "add new" it will automatically insert The PatientID from grid1 which is my patient table to PatientID column in grid2 which is my billing table. hope this make sence.



<%@ Page Title="" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="HomeHealthBilling.aspx.vb" Inherits="TherapistUserPage_HomeHealthBilling" %>
 
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
    <style type="text/css">
.RadGrid_Default{font:12px/16px "segoe ui",arial,sans-serif}.RadGrid_Default{border:1px solid #828282;background:#fff;color:#333}.RadGrid_Default{font:12px/16px "segoe ui",arial,sans-serif}.RadGrid_Default{border:1px solid #828282;background:#fff;color:#333}.RadGrid_Default .rgMasterTable{font:12px/16px "segoe ui",arial,sans-serif}.RadGrid .rgMasterTable{border-collapse:separate;border-spacing:0}.RadGrid_Default .rgMasterTable{font:12px/16px "segoe ui",arial,sans-serif}.RadGrid .rgMasterTable{border-collapse:separate;border-spacing:0}.RadGrid_Default .rgHeader{color:#333}.RadGrid_Default .rgHeader{border:0;border-bottom:1px solid #828282;background:#eaeaea 0 -2300px repeat-x url('mvwres://Telerik.Web.UI, Version=2012.2.607.40, Culture=neutral, PublicKeyToken=121fae78165ba3d4/Telerik.Web.UI.Skins.Default.Grid.sprite.gif')}.RadGrid .rgHeader{padding-top:5px;padding-bottom:4px;text-align:left;font-weight:normal}.RadGrid .rgHeader{padding-left:7px;padding-right:7px}.RadGrid .rgHeader{cursor:default}.RadGrid_Default .rgHeader{color:#333}.RadGrid_Default .rgHeader{border:0;border-bottom:1px solid #828282;background:#eaeaea 0 -2300px repeat-x url('mvwres://Telerik.Web.UI, Version=2012.2.607.40, Culture=neutral, PublicKeyToken=121fae78165ba3d4/Telerik.Web.UI.Skins.Default.Grid.sprite.gif')}.RadGrid .rgHeader{padding-top:5px;padding-bottom:4px;text-align:left;font-weight:normal}.RadGrid .rgHeader{padding-left:7px;padding-right:7px}.RadGrid .rgHeader{cursor:default}
        </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
    <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server">
    </telerik:RadStyleSheetManager>
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        <Scripts>
            <asp:ScriptReference Assembly="Telerik.Web.UI"
                Name="Telerik.Web.UI.Common.Core.js">
            </asp:ScriptReference>
            <asp:ScriptReference Assembly="Telerik.Web.UI"
                Name="Telerik.Web.UI.Common.jQuery.js">
            </asp:ScriptReference>
            <asp:ScriptReference Assembly="Telerik.Web.UI"
                Name="Telerik.Web.UI.Common.jQueryInclude.js">
            </asp:ScriptReference>
        </Scripts>
    </telerik:RadScriptManager>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    </telerik:RadAjaxManager>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"
     
         
         
        SelectCommand="SELECT [PatientID], [PatientLast], [PatientFirst] FROM [Patient]">
</asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server"
        ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"
        SelectCommand="SELECT [ClaimID], [PatientID], [TherapistID], [PayrollID], [StartDate], [AbsentUnits], [Units], [Notes] FROM [Billing\] WHERE ([PatientID] = @PatientID)"
         
        UpdateCommand="UPDATE [Billing\] SET [PatientID] = @PatientID, [TherapistID] = @TherapistID, [PayrollID] = @PayrollID, [StartDate] = @StartDate, [AbsentUnits] = @AbsentUnits, [Units] = @Units, [Notes] = @Notes WHERE [ClaimID] = @ClaimID"
        DeleteCommand="DELETE FROM [Billing\] WHERE [ClaimID] = @ClaimID"
         
         
         
        InsertCommand="INSERT INTO [Billing\] (PatientID) SELECT PatientID FROM Patient">
        <DeleteParameters>
            <asp:Parameter Name="ClaimID" Type="Int32" />
        </DeleteParameters>
        <SelectParameters>
            <asp:ControlParameter ControlID="RadGrid1" Name="PatientID"
                PropertyName="SelectedValue" Type="Int32" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="PatientID" Type="Int32" />
            <asp:Parameter Name="TherapistID" Type="Int32" />
            <asp:Parameter Name="PayrollID" Type="Int32" />
            <asp:Parameter Name="StartDate" Type="DateTime" />
            <asp:Parameter Name="AbsentUnits" Type="String" />
            <asp:Parameter Name="Units" Type="String" />
            <asp:Parameter Name="Notes" Type="String" />
            <asp:Parameter Name="ClaimID" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
    <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" PageSize="20"
        GridLines="None" Width="20%"
        CellSpacing="0" AllowCustomPaging="True" ShowFooter="True"
        ShowStatusBar="True" Skin="Metro" DataSourceID="SqlDataSource1"
        AutoGenerateDeleteColumn="True" AutoGenerateEditColumn="True"
        AllowAutomaticDeletes="True" AllowAutomaticInserts="True"
        AllowAutomaticUpdates="True">
        <ClientSettings AllowKeyboardNavigation="true" EnablePostBackOnRowClick="true">
            <Selecting AllowRowSelect="true" />
        </ClientSettings>
        <MasterTableView DataKeyNames="PatientID" AutoGenerateColumns="False"
            GridLines="Both" ShowFooter="False" DataSourceID="SqlDataSource1"
            EditMode="PopUp" >
            <DetailTables>
                <telerik:GridTableView runat="server"
                    DataKeyNames="PatientID" DataSourceID="SqlDataSource2" Name="Visits">
                    <ParentTableRelation>
                        <telerik:GridRelationFields DetailKeyField="PatientID"
                            MasterKeyField="PatientID" />
                    </ParentTableRelation>
                    <CommandItemSettings ExportToPdfText="Export to PDF" />
                    <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column"
                        Visible="True">
                    </RowIndicatorColumn>
                    <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column"
                        Visible="True">
                    </ExpandCollapseColumn>
                    <EditFormSettings>
                        <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                        </EditColumn>
                    </EditFormSettings>
                    <PagerStyle AlwaysVisible="True" Mode="Advanced" Visible="False" />
                </telerik:GridTableView>
            </DetailTables>
<CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
 
<RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column"></RowIndicatorColumn>
 
<ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column"></ExpandCollapseColumn>
 
            <Columns>
                <telerik:GridBoundColumn DataField="PatientID" DataType="System.Int32"
                    FilterControlAltText="Filter PatientID column" HeaderText="PatientID"
                    ReadOnly="True" SortExpression="PatientID" UniqueName="PatientID">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="PatientLast"
                    FilterControlAltText="Filter PatientLast column" HeaderText="PatientLast"
                    SortExpression="PatientLast" UniqueName="PatientLast">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="PatientFirst"
                    FilterControlAltText="Filter PatientFirst column" HeaderText="PatientFirst"
                    SortExpression="PatientFirst" UniqueName="PatientFirst">
                </telerik:GridBoundColumn>
            </Columns>
 
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
</EditFormSettings>
            <PagerStyle AlwaysVisible="True" />
        </MasterTableView>
        <PagerStyle Mode="Advanced" ShowPagerText="False" />
 
<FilterMenu EnableImageSprites="False"></FilterMenu>
    </telerik:RadGrid>
    <asp:CustomValidator ID="CustomValidator1" runat="server"
        ErrorMessage="CustomValidator"></asp:CustomValidator>
    <asp:FormView ID="FormView1" runat="server" DataKeyNames="ClaimID"
        DataSourceID="Units">
        <EditItemTemplate>
            ClaimID:
            <asp:Label ID="ClaimIDLabel1" runat="server" Text='<%# Eval("ClaimID") %>' />
            <br />
            PatientID:
            <asp:TextBox ID="PatientIDTextBox" runat="server"
                Text='<%# Bind("PatientID") %>' />
            <br />
            TherapistID:
            <asp:TextBox ID="TherapistIDTextBox" runat="server"
                Text='<%# Bind("TherapistID") %>' />
            <br />
            StartDate:
            <asp:TextBox ID="StartDateTextBox" runat="server"
                Text='<%# Bind("StartDate") %>' />
            <br />
            AbsentUnits:
            <asp:TextBox ID="AbsentUnitsTextBox" runat="server"
                Text='<%# Bind("AbsentUnits") %>' />
            <br />
            Units:
            <asp:TextBox ID="UnitsTextBox" runat="server" Text='<%# Bind("Units") %>' />
            <br />
            Notes:
            <asp:TextBox ID="NotesTextBox" runat="server" Text='<%# Bind("Notes") %>' />
            <br />
            <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
                CommandName="Update" Text="Update" />
             <asp:LinkButton ID="UpdateCancelButton" runat="server"
                CausesValidation="False" CommandName="Cancel" Text="Cancel" />
        </EditItemTemplate>
        <InsertItemTemplate>
            PatientID:
            <asp:TextBox ID="PatientIDTextBox" runat="server"
                Text='<%# Bind("PatientID") %>' />
            <br />
            TherapistID:
            <asp:TextBox ID="TherapistIDTextBox" runat="server"
                Text='<%# Bind("TherapistID") %>' />
            <br />
            StartDate:
            <asp:TextBox ID="StartDateTextBox" runat="server"
                Text='<%# Bind("StartDate") %>' />
            <br />
            AbsentUnits:
            <asp:TextBox ID="AbsentUnitsTextBox" runat="server"
                Text='<%# Bind("AbsentUnits") %>' />
            <br />
            Units:
            <asp:TextBox ID="UnitsTextBox" runat="server" Text='<%# Bind("Units") %>' />
            <br />
            Notes:
            <asp:TextBox ID="NotesTextBox" runat="server" Text='<%# Bind("Notes") %>' />
            <br />
            <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
                CommandName="Insert" Text="Insert" />
             <asp:LinkButton ID="InsertCancelButton" runat="server"
                CausesValidation="False" CommandName="Cancel" Text="Cancel" />
        </InsertItemTemplate>
        <ItemTemplate>
            ClaimID:
            <asp:Label ID="ClaimIDLabel" runat="server" Text='<%# Eval("ClaimID") %>' />
            <br />
            PatientID:
            <asp:Label ID="PatientIDLabel" runat="server" Text='<%# Bind("PatientID") %>' />
            <br />
            TherapistID:
            <asp:Label ID="TherapistIDLabel" runat="server"
                Text='<%# Bind("TherapistID") %>' />
            <br />
            StartDate:
            <asp:Label ID="StartDateLabel" runat="server" Text='<%# Bind("StartDate") %>' />
            <br />
            AbsentUnits:
            <asp:Label ID="AbsentUnitsLabel" runat="server"
                Text='<%# Bind("AbsentUnits") %>' />
            <br />
            Units:
            <asp:Label ID="UnitsLabel" runat="server" Text='<%# Bind("Units") %>' />
            <br />
            Notes:
            <asp:Label ID="NotesLabel" runat="server" Text='<%# Bind("Notes") %>' />
            <br />
            <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False"
                CommandName="Edit" Text="Edit" />
             <asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False"
                CommandName="Delete" Text="Delete" />
             <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False"
                CommandName="New" Text="New" />
        </ItemTemplate>
    </asp:FormView>
    <asp:SqlDataSource ID="Units" runat="server"
        ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"
        DeleteCommand="DELETE FROM [Billing\] WHERE [ClaimID] = @ClaimID"
        InsertCommand="INSERT INTO [Billing\] ([PatientID], [TherapistID], [StartDate], [AbsentUnits], [Units], [Notes]) VALUES (@PatientID, @TherapistID, @StartDate, @AbsentUnits, @Units, @Notes)"
        SelectCommand="SELECT [ClaimID], [PatientID], [TherapistID], [StartDate], [AbsentUnits], [Units], [Notes] FROM [Billing\] WHERE ([PatientID] = @PatientID)"
        UpdateCommand="UPDATE [Billing\] SET [PatientID] = @PatientID, [TherapistID] = @TherapistID, [StartDate] = @StartDate, [AbsentUnits] = @AbsentUnits, [Units] = @Units, [Notes] = @Notes WHERE [ClaimID] = @ClaimID">
        <DeleteParameters>
            <asp:Parameter Name="ClaimID" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="PatientID" Type="Int32" />
            <asp:Parameter Name="TherapistID" Type="Int32" />
            <asp:Parameter Name="StartDate" Type="DateTime" />
            <asp:Parameter Name="AbsentUnits" Type="String" />
            <asp:Parameter Name="Units" Type="String" />
            <asp:Parameter Name="Notes" Type="String" />
        </InsertParameters>
        <SelectParameters>
            <asp:ControlParameter ControlID="RadGrid1" Name="PatientID"
                PropertyName="SelectedValue" Type="Int32" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="PatientID" Type="Int32" />
            <asp:Parameter Name="TherapistID" Type="Int32" />
            <asp:Parameter Name="StartDate" Type="DateTime" />
            <asp:Parameter Name="AbsentUnits" Type="String" />
            <asp:Parameter Name="Units" Type="String" />
            <asp:Parameter Name="Notes" Type="String" />
            <asp:Parameter Name="ClaimID" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
    <telerik:radgrid ID="RadGrid2" ShowStatusBar="True" runat="server" AllowPaging="True"
        PageSize="5" DataSourceID="SqlDataSource2" GridLines="None" Width="95%"
        CellSpacing="0" AllowAutomaticDeletes="True" AllowAutomaticInserts="True"
        AllowAutomaticUpdates="True" AllowCustomPaging="True"
        AutoGenerateDeleteColumn="True" AutoGenerateEditColumn="True" ShowFooter="True"
        Skin="Metro">
        <MasterTableView Width="100%" AutoGenerateColumns="False" DataKeyNames="ClaimID"
            DataSourceID="SqlDataSource2" CommandItemDisplay="Top" ShowFooter="False"
            EditMode="PopUp">           
<CommandItemSettings ExportToPdfText="Export to PDF" AddNewRecordText="Add new visit"></CommandItemSettings>
 
<RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column"></RowIndicatorColumn>
 
<ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column"></ExpandCollapseColumn>
 
 
            <Columns>
                <telerik:GridBoundColumn DataField="ClaimID" DataType="System.Int32"
                    FilterControlAltText="Filter ClaimID column" HeaderText="ClaimID"
                    ReadOnly="True" SortExpression="ClaimID" UniqueName="ClaimID">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="PatientID" DataType="System.Int32"
                    FilterControlAltText="Filter PatientID column" HeaderText="PatientID"
                    SortExpression="PatientID" UniqueName="PatientID">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="TherapistID"
                    FilterControlAltText="Filter TherapistID column" HeaderText="TherapistID"
                    SortExpression="TherapistID" UniqueName="TherapistID"
                    DataType="System.Int32">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="PayrollID"
                    FilterControlAltText="Filter PayrollID column" HeaderText="PayrollID"
                    SortExpression="PayrollID" UniqueName="PayrollID" DataType="System.Int32">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="StartDate"
                    FilterControlAltText="Filter StartDate column" HeaderText="StartDate"
                    SortExpression="StartDate" UniqueName="StartDate"
                    DataType="System.DateTime">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="AbsentUnits"
                    FilterControlAltText="Filter AbsentUnits column" HeaderText="AbsentUnits"
                    SortExpression="AbsentUnits" UniqueName="AbsentUnits">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Units"
                    FilterControlAltText="Filter Units column" HeaderText="Units"
                    SortExpression="Units" UniqueName="Units">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Notes"
                    FilterControlAltText="Filter Notes column" HeaderText="Notes"
                    SortExpression="Notes" UniqueName="Notes">
                </telerik:GridBoundColumn>
            </Columns>
 
 
<EditFormSettings UserControlName="Home Health Billing">
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
</EditFormSettings>
            <PagerStyle AlwaysVisible="True" />
        </MasterTableView>
        <ClientSettings AllowKeyboardNavigation="true" EnablePostBackOnRowClick="true">
            <Selecting AllowRowSelect="true" />
            <Resizing AllowResizeToFit="True" />
        </ClientSettings>
        <PagerStyle Mode="Advanced" AlwaysVisible="True" />
 
<FilterMenu EnableImageSprites="False"></FilterMenu>
    </telerik:RadGrid>
    <br />
     
     
    </asp:Content>



VB


Imports System
Imports System.Web.UI
Imports Telerik.Web.UI
Imports System.Data.SqlClient
Imports System.Data
 
 
Partial Class TherapistUserPage_HomeHealthBilling
    Inherits System.Web.UI.Page
 
    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        If RadGrid1.SelectedIndexes.Count = 0 Then
            RadGrid1.SelectedIndexes.Add(0)
        End If
        If RadGrid2.SelectedIndexes.Count = 0 Then
            RadGrid2.Rebind()
            RadGrid2.SelectedIndexes.Add(0)
        End If
    End Sub
 
 
 
    Protected Sub RadGrid2_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid2.NeedDataSource
 
 
    End Sub
 
     
 
End Class
0
Kostadin
Telerik team
answered on 21 Sep 2012, 07:29 AM
Hello Alex,

I already answered your support ticket but I will explain it here as well if somebody else has similar requirements.
I populated the TextBox with details form the FormView which you have in your project. In ItemDataBound event handler I check whether you are inserting new data, and if you are inserting I find the Label control with ID=PatientIDLabel and take its value. Here is the code:
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs) Handles RadGrid2.ItemDataBound
    If RadGrid2.MasterTableView.EditMode = GridEditMode.PopUp Then
        If TypeOf e.Item Is GridEditFormInsertItem AndAlso e.Item.OwnerTableView.IsItemInserted Then
            Dim insertItem As GridEditFormInsertItem = DirectCast(e.Item, GridEditFormInsertItem)
            Dim value As String = DirectCast(FormView1.FindControl("PatientIDLabel"), Label).Text
            Dim txt As TextBox = DirectCast(insertItem("PatientID").Controls(0), TextBox)
            txt.Text = value
            txt.Enabled = False
        End If
    End If
End Sub


Kind regards,
Kostadin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Alex
Top achievements
Rank 1
answered on 23 Sep 2012, 04:47 PM

Sorry Now that I take a deeper look I have a few problems. First Problem It does automatically populate the PatientID and it inserts it but it does not inset the rest of the values that I fill out such as units and notes and so on. All it does when I click insert is insert the patient ID. I need it to also insert the values I type in. Second problem is form view I actually forgot to delete that because I actually don't need it so is there a way to populate the patient ID without having form view on this project. One more question I will also need to auto populate the TherapistID by who is logged in by like a profile control not sure that's what it is called. So here is the how this web page will work. Therapist will log in and only see the Patients that are assigned to them. They will be able to click on grid 1 which is the patient list and grid 2 will populate all the visits that the therapist has for that selected patient. they will also be able to add new visits that's where all this comes into play. So when the therapist clicks add new visit this is where patient ID and TherapistID will automatically populate. They don't necessarily need to be visible on the grid I just had them like that because I wanted to see that the IDs where being populated. Hope this makes sense thanks so much for your help.

0
Accepted
Kostadin
Telerik team
answered on 24 Sep 2012, 01:39 PM
Hi Alex,

A possible approach is when a row is selected to save the PatientID in ViewState and when the InsertCommand is fired to populate the TextBox with the value from ViewState.
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs) Handles RadGrid2.ItemDataBound
 
 
        If RadGrid2.MasterTableView.EditMode = GridEditMode.PopUp Then
            If TypeOf e.Item Is GridEditFormInsertItem AndAlso e.Item.OwnerTableView.IsItemInserted Then
                Dim insertItem As GridEditFormInsertItem = DirectCast(e.Item, GridEditFormInsertItem)
                Dim txt As TextBox = DirectCast(insertItem("PatientID").Controls(0), TextBox)
                Dim value As String
                If ViewState("CurrentPatientID") IsNot Nothing Then
                    value = DirectCast(ViewState("CurrentPatientID"), String)
                End If
                txt.Text = value
                txt.Enabled = False
            End If
        End If
 
    End Sub
     
    Dim PatientID As String
    Protected Sub RadGrid1_ItemCommand(sender As Object, e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand
        If e.CommandName = "RowClick" Then
            Dim index As Integer = e.Item.ItemIndex
            Dim item As GridDataItem = DirectCast(RadGrid1.Items(index), GridDataItem)
            PatientID = item("PatientID").Text
            ViewState("CurrentPatientID") = PatientID
        End If
    End Sub

I also answered your support ticket. If you would like we can continue our conversation there.

Greetings,
Kostadin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Alex
Top achievements
Rank 1
answered on 24 Sep 2012, 06:29 PM
thank you
Tags
Grid
Asked by
Alex
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Shinu
Top achievements
Rank 2
Alex
Top achievements
Rank 1
Kostadin
Telerik team
Share this question
or