Hi
I have a page which contains a grid of properties (all managed by one letting agency). I have another page which contains a grid of tenants (all of the tenants in properties managed by the letting agency). Both grids work perfectly and I am using an embedded form on each to provide insert/updates for both the properties and the tenants.
I have a situation where I want to be able to make the NAME of the tenant clickable on the PROPERTY screen and take the user to the Tenant Management Screen with the tenant they clicked in EDIT MODE.
I've worked out how to get the correct hyperlink in the format http://localhost/data_tenantmanagement.aspx?action=edit&id=TENANT_ID
My tenant management grid has filters and tooltips so that when someone hovers over the name it pops out contact details. The TenantPerson table has an ID number (primary key) and the Property record has a field called TENANTID which maps to the tenant living in it.
This code is in data_tenantmanagement.aspx.vb:
Public Function GetDataTable(ByVal query As String) As DataTable
Dim ConnString As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
Dim conn As SqlConnection = New SqlConnection(ConnString)
Dim adapter As SqlDataAdapter = New SqlDataAdapter
adapter.SelectCommand = New SqlCommand(query, conn)
Dim table1 As New DataTable
conn.Open()
Try
adapter.Fill(table1)
Finally
conn.Close()
End Try
Return table1
End Function
Public ReadOnly Property TheseTenants() As DataTable
Get
Dim obj As Object = Me.Session("TheseTenants")
If (Not obj Is Nothing) Then
Return CType(obj, DataTable)
End If
Dim myDataTable As DataTable = New DataTable
myDataTable = GetDataTable("SELECT * FROM TenantPerson")
Me.Session("TheseTenants") = myDataTable
Return myDataTable
End Get
End Property
Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
Me.RadGrid1.DataSource = Me.TheseTenants
Me.TheseTenants.PrimaryKey = New DataColumn() {Me.TheseTenants.Columns("Id")}
End Sub
Protected Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGrid1.PreRender
If Not IsPostBack And Me.RadGrid1.MasterTableView.Items.Count > 0 Then
RadGrid1.EditIndexes.Clear()
Me.Session("TheseTenants") = Nothing
RadGrid1.DataSource = TheseTenants
RadGrid1.DataBind()
End If
End Sub
I guess I need:
1. Generate the hyperlink from the PROPERTY screen to the TENANT screen with an action (edit) and an ID (the tenant ID).
2. Open the data_tenantmanagement.aspx page and somewhere read the ID of the tenant being passed in.
3. Find the row corresponding to the required tenant.
4. Open the row in Edit Mode.
The bit of the grid with the EDIT is this (ignore the drag and drop stuff):
<EditColumn FilterControlAltText="Filter EditCommandColumn1 column" UniqueName="EditCommandColumn1">
</EditColumn>
<FormTemplate>
<telerik:RadToolTipManager ID="RadToolTipManager1" runat="server" AutoTooltipify="True" Position="MiddleRight" RelativeTo="Element"></telerik:RadToolTipManager>
<div class="widget">
<header>
<div class="pull-left">
<h2>
<asp:Literal ID="litControlTitle" runat="server"></asp:Literal>
</h2>
</div>
</header>
<div class="inner-padding">
<div class="row">
<div class="col-sm-2">
<label for="txtDisplayName">
Display Name:
</label>
</div>
<div class="col-sm-2">
<Telerik:RadTextBox skin="Bootstrap" ID="txtDisplayName" runat="server" ToolTip="Enter the display name here (this will appear in drop down lists referring to this entity) - REQUIRED." />
</div>
</div>
<div class="row">
<div class="col-sm-2">
<label for="lstPeople">
People:
</label>
<telerik:RadComboBox ID="drpPeopleSearch" runat="server" Width="200px" Height="400px"
EmptyMessage="Type a name..." ClientIDMode="Static" AllowCustomText="true" AutoCompleteSeparator="|" Filter="Contains" MarkFirstMatch="True" onclientselectedindexchanged="OnClientSelectedIndexChanged" DropDownWidth="250px" ToolTip="Start typing a name and click the one you need when it is showing." Skin="Web20">
</telerik:RadComboBox>
</div>
<div class="col-sm-2">
<label for="lstTenant">
Tenant Object:
</label>
</div>
<div class="col-sm-2">
<label for="txtLeadTenant">
Lead Tenant Person:
</label>
</div>
<div class="col-sm-4">
<div class="row">
<asp:Button ID="btnUpdate" runat="server" CommandName='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "PerformInsert", "Update")%>' Text='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "Insert", "Update") %>' CssClass="btn btn-primary" ValidationGroup="EditFormGroup" CausesValidation="True" ToolTip="Click this button to update or insert an entity." />
<asp:Button ID="btnCancel" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" CssClass="btn btn-default" ToolTip="Click this button to cancel out of the insert/edit form." />
<asp:TextBox ID="txtid" runat="server" Text="" style="visibility: hidden;" />
</div>
<div class="spacer-20"></div>
<div class="row">
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ValidationGroup="EditFormGroup" Visible="False" CssClass="alert alert-danger" />
<asp:RequiredFieldValidator ValidationGroup="EditFormGroup" ID="RequiredFieldValidator1" runat="server" ErrorMessage="You must enter a display name." Text="" ClientIDMode="Static" ControlToValidate="txtDisplayName" SetFocusOnError="True" Display="Dynamic" Visible="True"></asp:RequiredFieldValidator>
<asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="txtNumberOfTenants" Text="" ErrorMessage="You must have at least one legal person in the Tenant Object." MaximumValue="4" MinimumValue="1" Type="Integer" ValidationGroup="EditFormGroup" Display="Dynamic" Visible="True"></asp:RangeValidator>
<asp:RangeValidator ID="RangeValidator2" runat="server" ControlToValidate="txtNumberOfLeadTenants" Text="" ErrorMessage="You must have a lead tenant defined." MaximumValue="1" MinimumValue="1" Type="Integer" ValidationGroup="EditFormGroup" Display="Dynamic" Visible="True"></asp:RangeValidator>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-2">
<telerik:RadListBox ID="lstPeople" runat="server" AllowTransfer="True" ButtonSettings-ShowDelete="False" ButtonSettings-ShowReorder="False" ButtonSettings-ShowTransferAll="False" ButtonSettings-TransferButtons="TransferFrom" CausesValidation="False" Culture="en-GB" EnableDragAndDrop="True" Height="200px" Skin="Bootstrap" TransferMode="Copy" Width="200px" TransferToID="lstTenant" AllowTransferOnDoubleClick="True" AutoPostBackOnTransfer="False" OnClientTransferred="onClientTransferredHandlerLstTenant" OnClientTransferring="onClientTransferringHandlerLstTenant" ClientIDMode="Static" ToolTip="Drag a name from here to the Tenant Object. You can filter this list using the box above.">
</telerik:RadListBox>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ABBEYMOVEConnectionString %>" SelectCommand="SELECT [Id], [LegalName] FROM [LegalPerson]"></asp:SqlDataSource>
</div>
<div class="col-sm-2">
<telerik:RadListBox ID="lstTenant" runat="server" AllowDelete="true" AllowReorder="true" AllowTransfer="True" CausesValidation="False" Culture="en-GB" EnableDragAndDrop="true" Height="200px" Skin="Bootstrap" TransferMode="Copy" TransferToID="lstLeadTenant" Width="200px" OnClientDeleted="onClientDeletedTenantHandler" AllowTransferOnDoubleClick="True" OnClientTransferred="onClientTransferredHandlerLstLeadTenant" ClientIDMode="Static"
OnClientTransferring="onClientTransferringHandlerLstLeadTenant" ButtonSettings-ShowTransferAll="False" ButtonSettings-TransferButtons="TransferFrom" ToolTip="Drag a person from here to the Lead Tenant box to the right.">
</telerik:RadListBox>
<asp:TextBox ID="txtNumberOfTenants" runat="server" CausesValidation="True" ValidationGroup="EditFormGroup" ClientIDMode="Static" TextMode="Number" style="visibility: hidden;"></asp:TextBox>
</div>
<div class="col-sm-2">
<telerik:RadListBox ID="lstLeadTenant" runat="server" AllowDelete="true" AutoPostBackOnDelete="False" CausesValidation="False" Culture="en-GB" EnableDragAndDrop="true" Height="200px" Skin="Bootstrap" Width="200px" OnClientDeleted="onClientDeletedLeadTenantHandler" ClientIDMode="Static" ToolTip="Use the delete button if you want to change the lead tenant person.">
</telerik:RadListBox>
<asp:TextBox ID="txtNumberOfLeadTenants" runat="server" CausesValidation="True" text="0" ValidationGroup="EditFormGroup" TextMode="Number" style="visibility: hidden;"></asp:TextBox>
</div>
</div>
</div>
</div>
</div>
</div>
</FormTemplate>
</EditFormSettings>
Any help would be appreciated as I've got to do this in several places (such as Owners, Landlords, etc.) - it's probably simple but I cannot work out where to put the bit that will actually do what I need. Of course, if request.querystring("action") isn't EDIT then I'd just want the grid to display as usual BUT if possible can I also throw action=NEW at it and put it in Insert Mode (or is that too much to ask).....
Thanks!