I have a project that I have been away from for a period of time and everything was working just fine, but when I came back to it to complete development, I have run into an issue with some of the grids not showing data in columns, but rather just "dumping it" in one long string.
I have attached a screen capture of the result, as well as display file and code behind. Any chance you can tell me why the grid is doing this?
Thanks in advance for any assistance!
Lynn
I have attached a screen capture of the result, as well as display file and code behind. Any chance you can tell me why the grid is doing this?
Thanks in advance for any assistance!
Lynn
<
asp:Content
ID
=
"Content2"
ContentPlaceHolderID
=
"ContentPlaceHolder1"
runat
=
"server"
>
<
h3
>
<
asp:Label
ID
=
"ListHeader"
runat
=
"server"
Text
=
"Agents"
></
asp:Label
>
</
h3
>
<
p
>
<
asp:Label
ID
=
"ListExplanation"
runat
=
"server"
Text
=
"Real estate agents in your organization"
></
asp:Label
>
</
p
>
<
div
class
=
"container"
>
<
div
class
=
"row10"
>
<
div
class
=
"one column"
>
</
div
>
<
div
class
=
"fourteen columns"
>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AllowSorting
=
"True"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
Width
=
"99.7%"
AutoGenerateColumns
=
"false"
AllowPaging
=
"false"
OnItemDataBound
=
"RadGrid1_ItemDataBound"
AllowFilteringByColumn
=
"True"
>
<
ExportSettings
HideStructureColumns
=
"true"
Csv-ColumnDelimiter
=
"Comma"
IgnorePaging
=
"true"
OpenInNewWindow
=
"true"
ExportOnlyData
=
"true"
>
</
ExportSettings
>
<
MasterTableView
Width
=
"100%"
CommandItemDisplay
=
"Top"
EnableViewState
=
"true"
>
<
PagerStyle
Mode
=
"Slider"
></
PagerStyle
>
<
CommandItemTemplate
>
<
table
class
=
"rcCommandTable"
width
=
"100%"
>
<
tr
>
<
td
style
=
"float: right; vertical-align:middle;"
>
<
asp:ImageButton
runat
=
"server"
ID
=
"btnCSVExport"
ImageUrl
=
"../Icons/csvdownload.jpg"
CommandName
=
"ExportToCSV"
Height
=
"24px"
Width
=
"24px"
ToolTip
=
"Export to CSV"
/>
<
asp:ImageButton
runat
=
"server"
ID
=
"btnExcelExport"
ImageUrl
=
"../Icons/excel.png"
CommandName
=
"ExportToExcel"
Height
=
"24px"
Width
=
"24px"
ToolTip
=
"Export to Excel"
/>
<
asp:ImageButton
runat
=
"server"
ID
=
"btnWordExport"
ImageUrl
=
"../Icons/ms_word_2.png"
CommandName
=
"ExportToWord"
Height
=
"24px"
Width
=
"24px"
ToolTip
=
"Export to Word"
/>
</
td
>
</
tr
>
</
table
>
</
CommandItemTemplate
>
<
CommandItemSettings
ShowExportToWordButton
=
"true"
ShowExportToExcelButton
=
"true"
ShowExportToCsvButton
=
"true"
ShowExportToPdfButton
=
"false"
>
</
CommandItemSettings
>
</
MasterTableView
>
</
telerik:RadGrid
>
</
div
>
<
div
class
=
"one column"
>
</
div
>
</
div
>
</
div
>
protected
void
Page_Init(
object
sender, System.EventArgs e)
{
if
(!Page.IsPostBack)
{
sType = Request[
"T"
];
// Get the users form security rules and set the buttons accordingly
string
sUserFormRules = Convert.ToString(Session[
"UserBrokerPlusFormsRules"
]);
string
sRule =
""
;
switch
(sType)
{
case
"A"
:
// Active
this
.ListHeader.Text =
"Active Agents"
;
this
.ListExplanation.Text =
"Real estate agents presently working for your organization"
;
sRule = sUserFormRules.Substring(21, 1);
break
;
case
"I"
:
// Inactive
this
.ListHeader.Text =
"Inactive Agents"
;
this
.ListExplanation.Text =
"Real estate agents that are not working for your organization but are still on the roster"
;
sRule = sUserFormRules.Substring(22, 1);
break
;
case
"T"
:
// Terminated
this
.ListHeader.Text =
"Terminated Agents"
;
this
.ListExplanation.Text =
"Real estate agents that worked for your organization in the past"
;
sRule = sUserFormRules.Substring(23, 1);
break
;
default
:
Response.Redirect(
"~/UserNotAuthorized.aspx"
);
break
;
}
switch
(sRule)
{
case
"0"
:
// the user is not authorized for this page, so send them to the error page
Response.Redirect(
"~/UserNotAuthorized.aspx"
);
break
;
case
"1"
:
// The user is only authorized for read-only activities, so set the buttons accordingly
this
.CreateNew.Enabled =
false
;
break
;
case
"2"
:
// The user is authorized to update data, so leave the buttons as is
break
;
}
this
.RadGrid1.AllowFilteringByColumn =
true
;
GridHyperLinkColumn hypercolumn =
null
;
GridBoundColumn boundcolumn =
null
;
hypercolumn =
new
GridHyperLinkColumn();
this
.RadGrid1.Columns.Add(hypercolumn);
hypercolumn.HeaderText =
"Edit"
;
hypercolumn.UniqueName =
"Agent"
;
hypercolumn.Text =
"<img border=\"0\" alt=\"View\" src=\"../Icons/pencil_16.png\" />"
;
hypercolumn.DataNavigateUrlFields =
new
string
[] {
"Agent"
};
hypercolumn.DataNavigateUrlFormatString =
"OfcAgentEdit.aspx?M=Y&T="
+ sType +
"K="
+
"{"
+
"0"
+
"}"
;
hypercolumn.AllowFiltering =
false
;
hypercolumn.HeaderStyle.Width = Unit.Pixel(50);
hypercolumn.Exportable =
false
;
hypercolumn =
null
;
hypercolumn =
new
GridHyperLinkColumn();
this
.RadGrid1.Columns.Add(hypercolumn);
hypercolumn.HeaderText =
"Email"
;
hypercolumn.UniqueName =
"SendAgentMail"
;
hypercolumn.Text =
"<img border=\"0\" alt=\"View\" src=\"../Icons/mailIcon.gif\" />"
;
hypercolumn.DataNavigateUrlFields =
new
string
[] {
"AgentEmail"
};
hypercolumn.DataNavigateUrlFormatString =
"mailto:"
+
"{"
+
"0"
+
"}"
;
hypercolumn.HeaderStyle.Width = Unit.Pixel(30);
hypercolumn.AllowFiltering =
false
;
hypercolumn.Exportable =
false
;
hypercolumn =
null
;
boundcolumn =
new
GridBoundColumn();
this
.RadGrid1.Columns.Add(boundcolumn);
boundcolumn.UniqueName =
"AgentID"
;
boundcolumn.DataField =
"AgentID"
;
boundcolumn.HeaderText =
"ID"
;
boundcolumn.FilterControlWidth = Unit.Pixel(50);
boundcolumn.HeaderStyle.CssClass =
"mediumgridcol"
;
boundcolumn.ItemStyle.CssClass =
"mediumgridcol"
;
boundcolumn.FooterStyle.CssClass =
"mediumgridcol"
;
boundcolumn.Visible =
true
;
boundcolumn =
null
;
boundcolumn =
new
GridBoundColumn();
this
.RadGrid1.Columns.Add(boundcolumn);
boundcolumn.UniqueName =
"AgentFullName"
;
boundcolumn.DataField =
"AgentFullName"
;
boundcolumn.HeaderText =
"Name"
;
boundcolumn.HeaderStyle.Width = Unit.Pixel(240);
boundcolumn.FilterControlWidth = Unit.Pixel(100);
boundcolumn.Visible =
true
;
boundcolumn =
null
;
// this code is left here as a working example of displaying a short date in a RadGrid column
//boundcolumn = new GridBoundColumn();
//this.RadGrid1.Columns.Add(boundcolumn);
//boundcolumn.UniqueName = "NewsEndDate";
//boundcolumn.DataField = "NewsEndDate";
//boundcolumn.HeaderText = "End";
//boundcolumn.DataFormatString = "{0:MM/dd/yy}";
//boundcolumn.Visible = true;
//boundcolumn = null;
boundcolumn =
new
GridBoundColumn();
this
.RadGrid1.Columns.Add(boundcolumn);
boundcolumn.UniqueName =
"OfficeCommonName"
;
boundcolumn.DataField =
"OfficeCommonName"
;
boundcolumn.HeaderText =
"Office"
;
boundcolumn.FilterControlWidth = Unit.Pixel(100);
boundcolumn.HeaderStyle.CssClass =
"largegridcol"
;
boundcolumn.ItemStyle.CssClass =
"largegridcol"
;
boundcolumn.FooterStyle.CssClass =
"largegridcol"
;
boundcolumn.Visible =
true
;
boundcolumn =
null
;
boundcolumn =
new
GridBoundColumn();
this
.RadGrid1.Columns.Add(boundcolumn);
boundcolumn.UniqueName =
"AgentCellular"
;
boundcolumn.DataField =
"AgentCellular"
;
boundcolumn.HeaderText =
"Cellular"
;
boundcolumn.FilterControlWidth = Unit.Pixel(60);
boundcolumn.HeaderStyle.CssClass =
"smallgridcol"
;
boundcolumn.ItemStyle.CssClass =
"smallgridcol"
;
boundcolumn.FooterStyle.CssClass =
"smallgridcol"
;
boundcolumn.Visible =
true
;
boundcolumn =
null
;
boundcolumn =
new
GridBoundColumn();
this
.RadGrid1.Columns.Add(boundcolumn);
boundcolumn.UniqueName =
"AgentEmail"
;
boundcolumn.DataField =
"AgentEmail"
;
boundcolumn.HeaderText =
"Email"
;
boundcolumn.HeaderStyle.CssClass =
"smallgridcol"
;
boundcolumn.ItemStyle.CssClass =
"smallgridcol"
;
boundcolumn.FooterStyle.CssClass =
"smallgridcol"
;
boundcolumn.Visible =
true
;
boundcolumn.FilterControlWidth = Unit.Pixel(100);
boundcolumn =
null
;
RadGrid1.AllowPaging = Convert.ToBoolean(Session[
"ShowListsWithPaging"
]);
RadGrid1.PageSize = 20;
}
else
{
sType = Request[
"T"
];
}
}
protected
void
RadGrid1_ItemDataBound(
object
sender, Telerik.Web.UI.GridItemEventArgs e)
{
// this code is used to make filter columns visible/invisible as the grid grows/shrinks
if
(e.Item
is
GridFilteringItem)
{
GridFilteringItem Filter = (GridFilteringItem)e.Item;
Filter[
"AgentID"
].CssClass =
"mediumgridcol"
;
Filter[
"OfficeCommonName"
].CssClass =
"largegridcol"
;
Filter[
"AgentCellular"
].CssClass =
"smallgridcol"
;
Filter[
"AgentEmail"
].CssClass =
"smallgridcol"
;
}
//// this code is left here for a working example of modifying column contents in a RadGrid
//if (e.Item is GridDataItem)
//{
// GridDataItem dataBoundItem = e.Item as GridDataItem;
// string strColumnValue1 = dataBoundItem["VendorShowInLists"].Text;
// if (strColumnValue1 == "0")
// {
// dataBoundItem["VendorShowInLists"].Text = "No";
// }
// else
// {
// dataBoundItem["VendorShowInLists"].Text = "Yes";
// }
//}
}
protected
void
CreateNew_Click(
object
sender, EventArgs e)
{
Response.Redirect(
"OfcAgentEdit.aspx?M=N&K=&T="
+ sType);
}
public
DataTable GetDataTable()
{
String ConnString = System.Configuration.ConfigurationManager.ConnectionStrings[
"BrokerPlus"
].ConnectionString;
DataTable dt =
new
DataTable();
string
sStatusNeeded =
""
;
switch
(sType)
{
case
"A"
:
// Active
sStatusNeeded =
"Active"
;
break
;
case
"I"
:
// Inactive
sStatusNeeded =
"Inactive"
;
break
;
case
"T"
:
// Terminated
sStatusNeeded =
"Terminated"
;
break
;
default
:
Response.Redirect(
"~/UserNotAuthorized.aspx"
);
break
;
}
switch
(Convert.ToString(Session[
"UserDataProfile"
]))
{
case
"Enterprise"
:
using
(SqlConnection sqlcon =
new
SqlConnection(ConfigurationManager.ConnectionStrings[
"BrokerPlus"
].ConnectionString))
{
using
(SqlCommand cmd =
new
SqlCommand(
"Agents_GetAllByAgentType_And_Account"
, sqlcon))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(
new
SqlParameter(
"@AgentStatus"
, sStatusNeeded));
cmd.Parameters.Add(
new
SqlParameter(
"@AgentRecType"
,
"Agent"
));
cmd.Parameters.Add(
new
SqlParameter(
"@Account"
, Convert.ToInt32(Session[
"UserAccount"
])));
using
(SqlDataAdapter da =
new
SqlDataAdapter(cmd))
{
da.Fill(dt);
return
dt;
}
}
}
case
"Company"
:
using
(SqlConnection sqlcon =
new
SqlConnection(ConfigurationManager.ConnectionStrings[
"BrokerPlus"
].ConnectionString))
{
using
(SqlCommand cmd =
new
SqlCommand(
"Agents_GetAllByAgentType_And_Company"
, sqlcon))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(
new
SqlParameter(
"@AgentStatus"
, sStatusNeeded));
cmd.Parameters.Add(
new
SqlParameter(
"@AgentRecType"
,
"Agent"
));
cmd.Parameters.Add(
new
SqlParameter(
"@Company"
, Convert.ToInt32(Session[
"UserCompany"
])));
using
(SqlDataAdapter da =
new
SqlDataAdapter(cmd))
{
da.Fill(dt);
return
dt;
}
}
}
case
"Office"
:
using
(SqlConnection sqlcon =
new
SqlConnection(ConfigurationManager.ConnectionStrings[
"BrokerPlus"
].ConnectionString))
{
using
(SqlCommand cmd =
new
SqlCommand(
"Agents_GetAllByAgentType_And_Office"
, sqlcon))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(
new
SqlParameter(
"@AgentStatus"
, sStatusNeeded));
cmd.Parameters.Add(
new
SqlParameter(
"@AgentRecType"
,
"Agent"
));
cmd.Parameters.Add(
new
SqlParameter(
"@Office"
, Convert.ToInt32(Session[
"UserOffice"
])));
using
(SqlDataAdapter da =
new
SqlDataAdapter(cmd))
{
da.Fill(dt);
return
dt;
}
}
}
case
"Agent"
:
Response.Redirect(
"~/UserNotAuthorized.aspx"
);
break
;
}
return
dt;
}
protected
void
RadGrid1_NeedDataSource(
object
source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
RadGrid1.DataSource = GetDataTable();
}