I am using as a datasource for a detail table a SELECT command with two inner joins.
Should I use a stored procedure instead?
I cannot post the code because it contains greek characters.
I can upload the code somewhere if you want.
5 Answers, 1 is accepted
<%@ Page Language="C#" MasterPageFile="~/AjaxMasterPage.master" AutoEventWireup="true" CodeFile="role2main.aspx.cs" Inherits="Roles_Role2_role2main" Title="Untitled Page" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<telerik:RadTabStrip ID="RadTabStrip1" runat="server" SelectedIndex="0"
Skin="Inox" Width="100%" MultiPageID="RadMultiPage1">
<Tabs>
<telerik:RadTab runat="server"
Selected="True" Text="Κτίρια" PageViewID="RadPageView1">
</telerik:RadTab>
<telerik:RadTab runat="server"
Text="Καταχώρηση/Αλλαγή Κτιρίων" PageViewID="RadPageView2">
</telerik:RadTab>
<telerik:RadTab runat="server" Text="Καταχώρηση Πάγιων Εργασιών">
</telerik:RadTab>
<telerik:RadTab runat="server" Text="Καταχώρηση Πρόσθετων Εργασιών">
</telerik:RadTab>
<telerik:RadTab runat="server" Text="Καταχώρηση Τεχνικών Εργασιών">
</telerik:RadTab>
</Tabs>
</telerik:RadTabStrip>
<telerik:RadMultiPage ID="RadMultiPage1" runat="server" SelectedIndex="0">
<telerik:RadPageView ID="RadPageView1" runat="server" Selected="True">
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" AllowFilteringByColumn="True"
AllowPaging="True" AllowSorting="True" DataSourceID="SqlDataSource1"
GridLines="None" PageSize="30" ShowGroupPanel="True" Skin="Telerik" ShowStatusBar="true"
Width="100%" AllowAutomaticDeletes="True" AllowAutomaticInserts="True"
AllowAutomaticUpdates="True" OnPreRender="RadGrid1_PreRender">
<PagerStyle Mode="NumericPages" />
<MasterTableView
DataSourceID="SqlDataSource1" Width="100%"
DataKeyNames="ROLE2_CODE,BUILDING_ID"
AllowMultiColumnSorting="True">
<HeaderStyle Width="200px" />
<DetailTables>
<telerik:GridTableView runat="server"
Caption="Πάγιες Εργασίες Κτιρίου"
DataSourceID="SqlDataSource2"
Width="100%"
TableLayout="Auto"
AutoGenerateColumns="False"
AllowSorting="False"
DataKeyNames="BUILDING_ID">
<ParentTableRelation>
<telerik:GridRelationFields
DetailKeyField="BUILDING_ID"
MasterKeyField="BUILDING_ID" />
</ParentTableRelation>
<RowIndicatorColumn>
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px" />
</ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn HeaderText="BUILDING_ID" HeaderButtonType="TextButton"
DataField="BUILDING_ID">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="PAGIA_ERGASIA_DATE" HeaderButtonType="TextButton"
DataField="PAGIA_ERGASIA_DATE">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="COMMENTS" HeaderButtonType="TextButton"
DataField="COMMENTS">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="PAGIA_ERGASIA_NAME" HeaderButtonType="TextButton"
DataField="PAGIA_ERGASIA_NAME">
</telerik:GridBoundColumn>
</Columns>
</telerik:GridTableView>
</DetailTables>
<RowIndicatorColumn>
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
<ExpandCollapseColumn visible="True">
<HeaderStyle Width="20px" />
</ExpandCollapseColumn>
<Columns>
<telerik:GridButtonColumn CommandName="Select" Text="Select"
UniqueName="column1">
</telerik:GridButtonColumn>
<telerik:GridBoundColumn
DataField="BUILDING_ID"
DataType="System.Int32"
HeaderText="BUILDING_ID"
SortExpression="BUILDING_ID"
UniqueName="BUILDING_ID">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn
DataField="ΟΔΟΣ"
DataType="System.String"
HeaderText="ΟΔΟΣ"
SortExpression="ΟΔΟΣ"
UniqueName="ΟΔΟΣ">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn
DataField="ΑΡΙΘΜΟΣ_ΟΔΟΥ"
DataType="System.Int32"
HeaderText="ΑΡΙΘΜΟΣ_ΟΔΟΥ"
SortExpression="ΑΡΙΘΜΟΣ_ΟΔΟΥ"
UniqueName="ΑΡΙΘΜΟΣ_ΟΔΟΥ">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn
DataField="ΤΚ"
DataType="System.String"
HeaderText="ΤΚ"
SortExpression="ΤΚ"
UniqueName="ΤΚ">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn
DataField="ΕΤΟΣ_ΚΑΤΑΣΚΕΥΗΣ"
DataType="System.DateTime"
HeaderText="ΕΤΟΣ_ΚΑΤΑΣΚΕΥΗΣ"
SortExpression="ΕΤΟΣ_ΚΑΤΑΣΚΕΥΗΣ"
UniqueName="ΕΤΟΣ_ΚΑΤΑΣΚΕΥΗΣ">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn
DataField="ROLE2_CODE"
DataType="System.String"
HeaderText="ROLE2_CODE"
SortExpression="ROLE2_CODE"
UniqueName="ROLE2_CODE"
Display="false">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn
DataField="ΕΙΔΟΣ_ΚΤΙΡΙΟΥ"
DataType="System.String"
HeaderText="ΕΙΔΟΣ_ΚΤΙΡΙΟΥ"
SortExpression="ΕΙΔΟΣ_ΚΤΙΡΙΟΥ"
UniqueName="ΕΙΔΟΣ_ΚΤΙΡΙΟΥ">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn
DataField="ΠΟΛΗ"
DataType="System.String"
HeaderText="ΠΟΛΗ"
SortExpression="ΠΟΛΗ"
UniqueName="ΠΟΛΗ">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn
DataField="ΠΕΡΙΟΧΗ"
DataType="System.String"
HeaderText="ΠΕΡΙΟΧΗ"
SortExpression="ΠΕΡΙΟΧΗ"
UniqueName="ΠΕΡΙΟΧΗ">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn
DataField="ΝΟΜΟΣ"
DataType="System.String"
HeaderText="ΝΟΜΟΣ"
SortExpression="ΝΟΜΟΣ"
UniqueName="ΝΟΜΟΣ">
</telerik:GridBoundColumn>
</Columns>
<EditFormSettings>
<EditColumn UniqueName="EditCommandColumn1">
</EditColumn>
</EditFormSettings>
</MasterTableView>
<ClientSettings AllowDragToGroup="True">
<Scrolling AllowScroll="True" UseStaticHeaders="True" />
<Resizing AllowColumnResize="True" ResizeGridOnColumnResize="True" />
</ClientSettings>
<FilterMenu EnableTheming="True" Skin="Telerik">
<CollapseAnimation Duration="200" Type="OutQuint" />
</FilterMenu>
</telerik:RadGrid>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:DiaxeirisiConnection %>"
SelectCommand="SELECT [BUILDING_ID], [ΟΔΟΣ], [ΑΡΙΘΜΟΣ_ΟΔΟΥ], [ΤΚ], [ΕΤΟΣ_ΚΑΤΑΣΚΕΥΗΣ], [ROLE2_CODE], [ΕΙΔΟΣ_ΚΤΙΡΙΟΥ], [ΠΟΛΗ], [ΠΕΡΙΟΧΗ], [ΝΟΜΟΣ] FROM [buildings]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:DiaxeirisiConnection %>"
SelectCommand="SELECT PAGIA_ERGASIA_DATE, COMMENTS, PAGIA_ERGASIA_NAME
FROM pagies_ergasies_schedule
INNER JOIN pagies_ergasies
ON pagies_ergasies_schedule.PAGIA_ERGASIA_ID = pagies_ergasies.PAGIA_ERGASIA_ID
INNER JOIN buildings_pagies_ergasies
ON pagies_ergasies.PAGIA_ERGASIA_ID = buildings_pagies_ergasies.PAGIA_ERGASIA_ID
WHERE buildings_pagies_ergasies.BUILDING_ID = @BUILDING_ID" >
<SelectParameters>
<asp:SessionParameter Name="BUILDING_ID" SessionField="BUILDING_ID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</telerik:RadPageView>
<telerik:RadPageView ID="RadPageView2" runat="server">
page2
</telerik:RadPageView>
</telerik:RadMultiPage>
</asp:Content>
Should I post it as a support ticket?
Thank you.
SelectCommand="SELECT buildings_pagies_ergasies.BUILDING_ID, PAGIA_ERGASIA_DATE, COMMENTS, PAGIA_ERGASIA_NAME
FROM pagies_ergasies_schedule
INNER JOIN pagies_ergasies
ON pagies_ergasies_schedule.PAGIA_ERGASIA_ID = pagies_ergasies.PAGIA_ERGASIA_ID
INNER JOIN buildings_pagies_ergasies
ON pagies_ergasies.PAGIA_ERGASIA_ID = buildings_pagies_ergasies.PAGIA_ERGASIA_ID
WHERE buildings_pagies_ergasies.BUILDING_ID = @BUILDING_ID" >
and now I am getting the following error :
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 28: foreach (GridDataItem data in RadGrid1.Items)
Line 29: {
Line 30: if (data.GetDataKeyValue("role2_code").ToString() == UserID)Line 31: {
Line 32: data.Visible = true;
|
Here is the code behind the page :
using
System;
using
System.Collections;
using
System.Configuration;
using
System.Data;
using
System.Linq;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.HtmlControls;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Xml.Linq;
using
Telerik.Web.UI;
public
partial class Roles_Role2_role2main : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
MembershipUser myObject = Membership.GetUser();
string UserID = myObject.ProviderUserKey.ToString();
foreach (GridDataItem data in RadGrid1.Items)
{
if (data.GetDataKeyValue("role2_code").ToString() == UserID)
{
data.Visible =
true;
}
else
{
data.Visible =
false;
}
}
}
}
Could you please try modifying your code as below and check if it makes any difference:
foreach (GridDataItem data in RadGrid1.Items) |
{ |
if (data.GetDataKeyValue("ROLE2_CODE").ToString() == UserID) |
{ |
data.Visible = true; |
} |
else |
{ |
data.Visible = false; |
} |
} |
Let me know how it goes.
Kind regards,
Iana
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.