RadListView insertitemtemplate still showing after insert - asp.net

I have a pretty simple scenario using manual data operations with rad list view. I insert an item into my collection in the ItemInserting event, the listview shows the new item but the insertitemtemplate is still showing. Is my setup wrong? Do I have to manually hide the thing?
Markup
<%# Page Language="VB" AutoEventWireup="false" CodeFile="Test2.aspx.vb" Inherits="Test2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<telerik:RadScriptManager runat="server" ID="rsm"></telerik:RadScriptManager>
<div>
<telerik:RadListView ID="rlv" runat="server" DataKeyNames="UserID" ItemPlaceholderID="itemPlaceholder" Height="400px" AllowPaging="true">
<InsertItemTemplate>
<tr>
<td>
<div style="vertical-align: middle; white-space: nowrap;">
<asp:LinkButton ID="btnInsert2" runat="server" Text="Insert" CommandName='<%# Telerik.Web.UI.RadListView.PerformInsertCommandName %>'></asp:LinkButton>
<asp:LinkButton ID="btnCancel2" runat="server" Text="Cancel" CommandName='<%# Telerik.Web.UI.RadListView.CancelCommandName %>'></asp:LinkButton>
</div>
</td>
<td>
<div style="vertical-align: middle; white-space: nowrap;">
<telerik:RadComboBox id="RadComboBox1" runat="server" autopostback="True" causesvalidation="False" allowcustomtext="True" backcolor="White" emptymessage="Select a Person" enableloadondemand="True" showmoreresultsbox="True" width="150px" dropdownwidth="200px" zindex="9002" enablescreenboundarydetection="False" style="margin-bottom: 0px" datatextfield="UserName" datavaluefield="pkUserID" filter="Contains" onitemsrequested="RCB_ItemsRequested">
<CollapseAnimation Duration="200" Type="OutQuint" />
</telerik:RadComboBox>
</div>
</td>
</tr>
</InsertItemTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Literal ID="lName" runat="server" Text='<%# Eval("UserName") %>'></asp:Literal>
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<asp:LinkButton ID="btnInsert" runat="server" CausesValidation="False" CommandName='<%# Telerik.Web.UI.RadListView.InitInsertCommandName %>' Text="Add User" />
<table>
<tr>
<td style="border: ridge 1px lightgray">
<strong>Applicable Users</strong>
<table>
<asp:PlaceHolder runat="server" ID="itemPlaceholder"></asp:PlaceHolder>
</table>
</td>
</tr>
</table>
</LayoutTemplate>
</telerik:RadListView>
</div>
</form>
</body>
</html>
Code Behind
Partial Class Test2
Inherits System.Web.UI.Page
Public Property Users As IList(Of UserInfo)
Get
Return If(ViewState("Users"), New List(Of UserInfo))
End Get
Set(ByVal value As IList(Of UserInfo))
ViewState("Users") = value
End Set
End Property
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Me.Users = GetInitialUsers()
End If
rlv.DataSource = Users
rlv.DataBind()
Me.ViewState.SetItemDirty("Users", True)
End Sub
Private Function GetInitialUsers() As IList(Of UserInfo)
Dim Users As New List(Of UserInfo)
Users.Add(New UserInfo(1, "1"))
Users.Add(New UserInfo(2, "2"))
Users.Add(New UserInfo(3, "2"))
Users.Add(New UserInfo(4, "4"))
Return Users
End Function
Protected Sub RCB_ItemsRequested(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs)
Dim ComboBox As Telerik.Web.UI.RadComboBox = sender
Dim itemOffset As Integer = e.NumberOfItems
Dim NumberOfItems As Integer = 1000000000
Dim Take As Integer = 20
For i As Integer = 0 To Take
ComboBox.Items.Add(New Telerik.Web.UI.RadComboBoxItem(i + itemOffset, (i + itemOffset).ToString))
Next
Dim NumberOfItemsInComboBox As Integer = e.NumberOfItems + ComboBox.Items.Count
If NumberOfItems > 0 Then
e.Message = [String].Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", NumberOfItemsInComboBox, NumberOfItems)
Else
e.Message = "No matches"
End If
e.EndOfItems = (NumberOfItemsInComboBox >= NumberOfItems)
End Sub
Protected Sub rlv_ItemInserting(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadListViewCommandEventArgs) Handles rlv.ItemInserting
Dim ComboBox As Telerik.Web.UI.RadComboBox = e.ListViewItem.FindControl("RadComboBox1")
If Not String.IsNullOrWhiteSpace(ComboBox.SelectedValue) Then
Dim UserID As Integer = ComboBox.SelectedValue
Dim UserName As String = ComboBox.Text
Me.Users.Add(New UserInfo(UserID, UserName))
Else
e.Canceled = True
End If
End Sub
<Serializable()>
Public Class UserInfo
Private _UserID As Integer
Private _UserName As String
Public ReadOnly Property UserID As Integer
Get
Return _UserID
End Get
End Property
Public ReadOnly Property UserName As String
Get
Return _UserName
End Get
End Property
Public Sub New(ByVal UserID As Integer, ByVal UserName As String)
_UserID = UserID
_UserName = UserName
End Sub
End Class
End Class

After you have inserted the new item, set the InsertItemPosition to None:
RadListView1.InsertItemPosition = RadListViewInsertItemPosition.None

radlistview1.IsItemInserted=false;
or set e.canceled=false after save click

Related

Dynamic page creation from db at run time in asp.net

I'm making E-Commerce website. Under that I want to show particular product details. From query string I can do that but that is not seo friendly so I need to make product name in url(from db) instead of using querystring. I tried following code but it is not working for me.
Error - The resource could not be Found
Global.asax
<%# Application Language="VB" %>
<%# Import Namespace="System.Web.Optimization" %>
<%# Import Namespace="System.Web.Routing" %>
<script runat="server">
Sub Application_Start(sender As Object, e As EventArgs)
RouteConfig.RegisterRoutes(RouteTable.Routes)
BundleConfig.RegisterBundles(BundleTable.Bundles)
End Sub
Private Shared Sub RegisterRoutes(routes As RouteCollection)
routes.MapPageRoute("product-detail", "{product_name}.aspx", "product-detail.aspx")
End Sub
</script>
product-detail.aspx (Dynamic Page)
Private Sub product_detail_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim pageName As String = Me.Page.RouteData.Values("product_name").ToString()
End If
End Sub
shop.aspx (used listview control to display list of products)
<asp:ListView ID="products" runat="server" DataKeyNames="ID">
<ItemTemplate>
<asp:HyperLink ID="productID" runat="server" NavigateUrl='<%# Eval("product_name", "~/{0}") %>' CssClass="product-link">
<!--blocks-starts--><div class="blocks blocks-shop">
<asp:Image ID="readyStock" runat="server" ImageUrl="images/common/ready_stock_tag.png" Visible="false" CssClass="tag" />
<asp:Label ID="checkReadyStock" runat="server" Visible="false"></asp:Label>
<div class="block-img">
<img src='<%# Eval("image") %>' runat="server" id="proImg" />
</div>
<div class="block-content">
<span class="sku" style="font-size:0.6em !important">Item No. <asp:Label ID="skuID" runat="server" Text='<%# Eval("sku") %>'></asp:Label></span>
<h3>
<asp:Label ID="prodName" runat="server" Text='<%# Eval("product_name") %>'></asp:Label></h3>
<p><strong>
<asp:Label ID="priceRange" runat="server" Text='<%# Eval("price_range") %>'></asp:Label></strong></p>
</div>
</div><!--blocks-ends-->
</asp:HyperLink>
</ItemTemplate>
<LayoutTemplate>
<div id="itemPlaceholderContainer" runat="server" style="">
<div runat="server" id="itemPlaceholder" />
</div>
</LayoutTemplate>
</asp:ListView>
shop.aspx.vb
Private Sub shop_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
Try
Dim str As String = "select * from products where status = 'active'"
Dim cmd As New MySqlCommand(str, con)
con.Open()
Dim da As New MySqlDataAdapter(cmd)
Dim dt As New DataTable
da.Fill(dt)
products.DataSource = dt
products.DataBind()
con.Close()
Catch ex As Exception
Response.Write(ex)
End Try
End If
End Sub

ListView Datapager not working When Session used instead of VeiwState

I want to display list of clinics details in listview. From MasterPage Users selects the city & If he goes to clinincs page then list of hospitals display from selected city. Now If I use ViewState in my clinics page then It does not gets clinics data from selected city So what I have done I store City session & on clinics page I have used Session instead of ViewState Which is now working right but my datagaer stopped working. If I have to see another page from datapager then it doesn't switch over. Here is my code
MasterPage
Protected Sub locationSelector_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles locationSelector.TextChanged
Session("masterLocation") = locationSelector.text
Session("Data") = Nothing
End Sub
Clinics Page
Private Sub hospitals_PreRender(sender As Object, e As EventArgs) Handles Me.PreRender
Try
If Not Session("Data") Is Nothing Then
hospitals.DataSource = Session("Data")
hospitals.DataBind()
Else
Dim citySelector As Label = Page.Master.FindControl("locationPopupActivator")
query = "select hospitalid, name, address, thumbnail, serviceID, mondayFrom, mondayTo, consultancyFees, city from hospitals Where city Like '" + citySelector.Text + "%' and status = 'active'"
Dim cmd As New MySqlCommand(query, con)
cmd.CommandTimeout = 120
Dim da As New MySqlDataAdapter(cmd)
Dim table As New DataTable
da.Fill(table)
Session("Data") = table
hospitals.DataSource = table
hospitals.DataBind()
End If
'mainCount.Text = table.Rows(0)("countRows").ToString
Catch ex As Exception
Response.Write(ex)
End Try
End Sub
Protected Sub DataPager1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
Try
Dim table As DataTable = Session("Data")
hospitals.DataSource = table
hospitals.DataBind()
Catch ex As Exception
Response.Write(ex)
End Try
End Sub
Listview on ASPX
<asp:ListView ID="hospitals" runat="server" DataKeyNames="hospitalID" DataKey="hospitalID">
<ItemTemplate>
My Content
</ItemTemplate>
<EmptyDataTemplate>
<div class="not-found">
<p>
Sorry! Selected Query Not Found</p>
<center>
<img src="images/not-found.jpg" /></center>
</div>
</EmptyDataTemplate>
<LayoutTemplate>
<ul id="itemPlaceholderContainer" runat="server" style="">
<li runat="server" id="itemPlaceholder" />
</ul>
<div class="datapager" style="padding-bottom: 10px;">
<asp:DataPager ID="DataPager1" runat="server" PageSize="10" PagedControlID="hospitals" ViewStateMode="Enabled">
<Fields>
<asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="false" ShowPreviousPageButton="true" ShowNextPageButton="false" />
<asp:NumericPagerField ButtonType="Link" />
<asp:NextPreviousPagerField ButtonType="Link" ShowNextPageButton="true" ShowLastPageButton="false" ShowPreviousPageButton="false" />
</Fields>
</asp:DataPager>
</div>
</LayoutTemplate>
</asp:ListView>
This is working sample of your page:
hospital.master
<%# Master Language="VB" CodeFile="hospital.master.vb" Inherits="hospital_master" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="sm" runat="server" />
<div>
<asp:Label ID="lblLockSel" runat="server" AssociatedControlID="locationSelector">Locator Selector</asp:Label>
<asp:UpdatePanel ID="upLocSel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox ID="locationSelector" runat="server" AutoPostBack="true"></asp:TextBox>
<asp:Label ID="locationPopupActivator" runat="server"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
hospital.master.vb
Partial Class hospital_master
Inherits System.Web.UI.MasterPage
Protected Sub locationSelector_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles locationSelector.TextChanged
Session("masterLocation") = locationSelector.Text
Session("Data") = Nothing
locationPopupActivator.Text = locationSelector.Text
End Sub
End Class
clinics.aspx
<%# Page Title="" Language="VB" MasterPageFile="~/hospital.master" AutoEventWireup="false" CodeFile="clinics.aspx.vb" Inherits="Clinics" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:UpdatePanel ID="upHospitals" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:ListView ID="hospitals" runat="server" DataKeyNames="hospitalID" DataKey="hospitalID">
<ItemTemplate>
<%--My Content--%>
<li>
<asp:HyperLink ID="lnkHospital" runat="server" NavigateUrl='<%#Eval("hospitalID", "~/hospital.aspx?id={0}") %>' Text='<%#Eval("Name") %>'></asp:HyperLink>
</li>
</ItemTemplate>
<EmptyDataTemplate>
<div class="not-found">
<p>
Sorry! Selected Query Not Found</p>
<center><%--<center>Is Deprecated Use div with CSS</center>--%>
<img src="images/not-found.jpg" /></center>
</div>
</EmptyDataTemplate>
<LayoutTemplate>
<ul>
<li runat="server" id="itemPlaceholder" />
</ul>
</LayoutTemplate>
</asp:ListView>
<%--Inside Update Panel dataPager should be outside paged control--%>
<div class="datapager" style="padding-bottom: 10px;">
<asp:DataPager ID="DataPager1" runat="server" PageSize="10" PagedControlID="hospitals"><%-- ViewStateMode="Enabled"> this is default--%>
<Fields>
<asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="false" ShowPreviousPageButton="true" ShowNextPageButton="false" />
<asp:NumericPagerField ButtonType="Link" />
<asp:NextPreviousPagerField ButtonType="Link" ShowNextPageButton="true" ShowLastPageButton="false" ShowPreviousPageButton="false" />
</Fields>
</asp:DataPager>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
clinics.aspx.vb
Partial Class Clinics
Inherits System.Web.UI.Page
Private Sub Clinics_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Session.Remove("Data") 'init
End If
End Sub
Private Sub hospitals_PagePropertiesChanging(sender As Object, e As PagePropertiesChangingEventArgs) Handles hospitals.PagePropertiesChanging
DataPager1.SetPageProperties(e.StartRowIndex, e.MaximumRows, False)
hospitals.DataSource = GetData() 'Session("Data")
hospitals.DataBind()
End Sub
Private Sub hospitals_PreRender(sender As Object, e As EventArgs) Handles Me.PreRender
hospitals.DataSource = GetData()
hospitals.DataBind()
End Sub
Private Function GetData() As Data.DataTable
Try
If Session("Data") IsNot Nothing Then
Return Session("Data")
Else
'This is MS SQL server. If you use MySQL then change types accordingly
DataPager1.SetPageProperties(0, DataPager1.PageSize, False) 'reinit
Dim citySelector As Label = Page.Master.FindControl("locationPopupActivator")
Using con As New Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("ClinicsCNN").ConnectionString)
Dim cmd As New Data.SqlClient.SqlCommand("select hospitalid, name, address, thumbnail, serviceID, mondayFrom, mondayTo, consultancyFees, city from hospitals Where city Like #city and status = 'active'", con)
cmd.CommandType = Data.CommandType.Text
cmd.Parameters.Add("#city", Data.SqlDbType.VarChar, 50).Value = citySelector.Text & "%" 'same as Session("masterLocation")
Dim table As New Data.DataTable()
Dim da As New Data.SqlClient.SqlDataAdapter(cmd)
da.Fill(table)
da.Dispose()
cmd.Dispose()
Session("Data") = table
Return table
End Using
End If
Catch ex As Exception
Response.Write(ex) 'for debug purpose
Return Nothing
End Try
End Function
End Class
Do you accept this solution?
Ok, after your comments here is my code that works for me:
Private Sub hospitals_PreRender(sender As Object, e As EventArgs) Handles Me.PreRender
Try
If Session("Data") Is Nothing Then
Dim citySelector As Label = Page.Master.FindControl("locationPopupActivator")
query = "select hospitalid, name, address, thumbnail, serviceID, mondayFrom, mondayTo, consultancyFees, city from hospitals Where city Like '" + citySelector.Text + "%' and status = 'active'"
Dim cmd As New MySqlCommand(query, con)
cmd.CommandTimeout = 120
Dim da As New MySqlDataAdapter(cmd)
Dim table As New DataTable
da.Fill(table)
Session("Data") = table
hospitals.DataSource = table
hospitals.DataBind()
End If
'mainCount.Text = table.Rows(0)("countRows").ToString
Catch ex As Exception
Response.Write(ex)
End Try
End Sub
protected void hospitals_PagePropertiesChanging(object sender, System.Web.UI.WebControls.PagePropertiesChangingEventArgs e)
{
var datapager = ((DataPager)hospitals.FindControl("DataPager1"));
datapager.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
hospitals.DataSource = Session["Data"];
hospitals.DataBind();
datapager.DataBind();
}
I don't think you need DataPager1_PreRender method at all so probably you should remove it all together. You will need to attach new event to your list view: OnPagePropertiesChanging="hospitals_PagePropertiesChanging". Sorry for code in c#, but I don't know VB very well ;)

Pass Text From a List View Controller to a OnClick Sub VB.Net

Is there a way to pass text from a List View controller to a OnClick Subroutine? For example, there's a label in the List View and I've attached a Button in the List View and attached an OnClick Subroutine to it. Now I want to pass the text from the Label over to the OnClick Subroutine. I hope this make sense. Down below is my code:
VB.Net Code:
Protected Sub AmButtonClick(ByVal sender As Object, ByVal e As System.EventArgs)
Dim url As String = CType(Me.AmListViewDetails.FindControl("merchantLink"), Label).Text
Dim sb As New StringBuilder()
sb.Append("<script type = 'text/javascript'>"_
sb.Append("window.open('")
sb.Append(url)
sb.Append("');")
sb.Append("</script>")
ClientScript.RegisterStartupScript(Me.GetType(), "script", sb.ToString())
End Sub
ASP.Net:
<asp:ListView runtat="server" ID="AmListViewDetails" ...>
<ItemTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<asp:Label ID="merchantLink" runat="server" Text='<%Eval("Link")%>' />
</td>
</tr>
<tr runat="server">
<td runat="server">
<asp:Button ID="AmBtn" runat="server" Text="Checkout" OnClick="AmButtonClick"/>
</td>
</tr>
</table>
</ItemTemplate>
</asp:ListView>
Add a CommandArgument property to the button. That's going to be the value passed to the event handler. You don't need an OnClick property.
<asp:Button ID="AmBtn" runat="server" Text="Checkout" CommandArgument="???" />
Your event handler would be
Sub AmListViewDetails_ItemCommand(object sender, ListViewCommandEventArgs e)
Dim valuePassedFromListView = Cstr(e.CommandArgument)
End Sub

How to get the current values of RadGrid Columns

I am using the follwing code.
in .aspx:
function AccessOnclient() {
debugger;
var grid = $find("<%= dg_InvPat.ClientID %>");
if (grid) {
var MasterTable = grid.get_masterTableView();
var sumtemp = 0;
var Rows = MasterTable.get_dataItems();
for (var i = 0; i < Rows.length; i++) {
var row = Rows[i];
var RadNumericTextBox1 = row.findControl("txt_projInv");
if (RadNumericTextBox1.get_value())
{
sumtemp =sumtemp + RadNumericTextBox1.get_value();
}
}
for (var i = 0; i < Rows.length; i++) {
var row = Rows[i];
var RadNumericTextBox1 = row.findControl("txt_projInv");
var valinv=RadNumericTextBox1.get_value();
var res=Math.round((valinv/sumtemp)*100);
var revpat = MasterTable.get_dataItems()[i].findElement("lbl_revpat");//access the Label control
revpat.innerText = res;
}
document.getElementById("ctl00_MainContent_b1").click();
}
}
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
<div id="content">
<table class="table_Style" width="100%">
<tr>
<td style="width: 15%">
<asp:Label ID="Label2" runat="server">Financial Year</asp:Label>
</td>
<td>
<Telerik:RadComboBox AutoPostBack="true" runat="server" ID="ddl_year" Width="200px"
MarkFirstMatch="true" CausesValidation="true" ValidationGroup="List">
</Telerik:RadComboBox>
<asp:Button ID="cmd_go" runat="server" Text="View" CausesValidation="true"
ValidationGroup="btnSubmit"></asp:Button>
<asp:CompareValidator ID="cvyear" runat="server" ErrorMessage="Please Select Financial Year"
ControlToValidate="ddl_year" ValueToCompare="Select" Operator="NotEqual" ValidationGroup="btnSubmit"></asp:CompareValidator>
</td>
</tr>
</table>
<table class="table_Style" width="100%">
<tr>
<td>
<Telerik:RadGrid ID="dg_InvPat" runat="server" AutoGenerateColumns="False" GridLines="None"
HeaderStyle-VerticalAlign="Top" Width="100%" ShowStatusBar="True" AllowPaging="True"
AllowSorting="false" AllowFilteringByColumn="False" PageSize="5">
<GroupingSettings CaseSensitive="false" />
<ExportSettings ExportOnlyData="true" OpenInNewWindow="True" IgnorePaging="true"
FileName="InvPattern">
</ExportSettings>
<MasterTableView CommandItemDisplay="None" CommandItemSettings-ShowRefreshButton="false"
CommandItemSettings-ShowAddNewRecordButton="false">
<RowIndicatorColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<NoRecordsTemplate>
<font color="red">No Records Available</font>
</NoRecordsTemplate>
<Columns>
<Telerik:GridBoundColumn UniqueName="NOTIF1" DataField="NOTIF1" HeaderText="As Per Notification" Visible ="false" >
</Telerik:GridBoundColumn>
<Telerik:GridBoundColumn UniqueName="NOTIF" DataField="NOTIF" HeaderText="As Per Notification">
</Telerik:GridBoundColumn>
<Telerik:GridBoundColumn UniqueName="CAT" DataField="CAT" HeaderText="Pattern Category">
</Telerik:GridBoundColumn>
<Telerik:GridBoundColumn UniqueName="INVESTMENT" DataField="INVESTMENT" HeaderText="Act Investment">
</Telerik:GridBoundColumn>
<Telerik:GridBoundColumn UniqueName="LIMITID" DataField="LIMITID" HeaderText="Limit Id"
Visible="false">
</Telerik:GridBoundColumn>
<Telerik:GridBoundColumn UniqueName="TRUSTPAT1" DataField="TRUSTPAT1" HeaderText="Trust Pattern" Visible="false">
</Telerik:GridBoundColumn>
<Telerik:GridBoundColumn UniqueName="TRUSTPAT" DataField="TRUSTPAT" HeaderText="Trust Pattern">
</Telerik:GridBoundColumn>
<Telerik:GridBoundColumn UniqueName="SHORTAGE" DataField="SHORTAGE" HeaderText="Shortfall/Excess">
</Telerik:GridBoundColumn>
<Telerik:GridTemplateColumn HeaderText="Project Investment">
<ItemTemplate>
<Telerik:RadNumericTextBox ID="txt_projInv" runat="server" EmptyMessage="" IncrementSettings-InterceptMouseWheel="false"
SkinID="RadTextYellow" Type="Number" DataType="System.Int64"
AutoPostBack="false" MaxLength="8" Text='<%# Bind("investment") %>'>
<NumberFormat DecimalDigits="0" GroupSeparator="" />
<ClientEvents OnKeyPress="AccessOnclient" OnValueChanged="AccessOnclient"/>
</Telerik:RadNumericTextBox>
</ItemTemplate>
</Telerik:GridTemplateColumn>
<Telerik:GridTemplateColumn HeaderText="Revised Pattern">
<ItemTemplate>
<asp:Label ID="lbl_revpat" runat="server" Text='<%# Bind("trustpat1") %>'></asp:Label>
</ItemTemplate>
</Telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</Telerik:RadGrid>
</td>
</tr>
<tr id="tr1">
<td colspan="2">
<table width="100%" border="0" >
<tr>
<td align="center">
<br/>
<div id="divgraph1" runat="server" >
<asp:Panel ID="pnlnum" runat="server" Width="100%" Visible="False" style="height:400px">
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
</asp:Panel>
</div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblhead" runat="server" Font-Size="10" ForeColor="#000033"
Font-Bold="True"></asp:Label>
</td>
<td align="right">
<asp:Label ID="lbltotal" runat="server" Font-Size="10" ForeColor="#000033"></asp:Label>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Label Width="100%" ID="lblmess" SkinID="lblErr" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Button id="b1" runat="server" />
</td>
</tr>
<tr>
<td colspan="2">
<Telerik:RadFormDecorator ID="RadFormDecorator1" runat="server" DecoratedControls="Default"
Skin="Sunset" Style="margin-bottom: 0px" />
<Telerik:RadWindowManager ID="RadWindowManager2" ShowContentDuringLoad="false" VisibleStatusbar="false"
ReloadOnShow="true" runat="server" Modal="true">
</Telerik:RadWindowManager>
</td>
</tr>
</table>
</div>
</asp:Content>
in .aspx.vb:
#Region "Namespaces"
Imports Telerik.Web.UI
Imports System.Data
Imports System.Net
Imports System
Imports System.IO
Imports System.Text
Imports System.Net.Mail
Imports InfoSoftGlobal.InfoSoftGlobal
#End Region
Partial Class iv
Inherits System.Web.UI.Page
#Region "Declarations"
Dim objEntry_ml As ClsPF_BE
Dim objEntry_bll As ClsPF_BLL
Dim ds As DataSet
Dim objCom_ml As Common_ml
Dim objCom_bll As Common_bll
Dim UserSysId As Long
Public UnitID As Integer
Public UnitName As String
Dim strXML As String
#End Region
#Region "PageEvents"
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
AddHandler Master.PageEvent, AddressOf Page_Load
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Master.UnitChange = True Then
Response.Redirect("iv.aspx")
End If
Master.PageHeadingTitle = "Pattern"
If Not Session("UserSysId") Is Nothing Then
UnitID = Session("UnitId")
UnitName = Session("UnitName")
UserSysId = Session("UserSysId")
Else
Response.Redirect("Login.aspx?Status=S")
End If
If Not IsPostBack Then
LoadYear()
End If
lblmess.Text = ""
End Sub
Protected Sub cmd_go_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmd_go.Click
LoadGrid()
Literal1.Text = DrawGraph()
pnlnum.Visible = True
divgraph1.Visible = True
End Sub
Private Sub LoadGrid()
Dim ds As New DataSet
Try
objEntry_ml = New ClsPF_BE
objEntry_bll = New ClsPF_BLL
Dim sReturnMessage As String = ""
objEntry_ml.FinYear_code = ddl_year.SelectedValue
ds = objEntry_bll.bll_Invpattern(objEntry_ml, UserSysId, sReturnMessage)
dg_InvPat.DataSource = ds
dg_InvPat.DataBind()
ds = Nothing
If dg_InvPat.Items.Count > 1 Then
lblmess.Visible = False
divgraph1.Visible = True
Else
lblmess.Text = "No records found for the year" & ddl_year.Text
lblmess.Visible = True
End If
Catch ex As Exception
End Try
End Sub
Sub LoadYear()
objEntry_ml = New ClsPF_BE
objEntry_bll = New ClsPF_BLL
ds = objEntry_bll.fillfinyear(objEntry_ml)
ddl_year.DataSource = ds
If ds.Tables(0).Rows.Count > 0 Then
ddl_year.DataValueField = ds.Tables(0).Columns(0).Caption
ddl_year.DataTextField = ds.Tables(0).Columns(1).Caption
ddl_year.DataBind()
If ddl_year.Items.Count > 0 Then
ddl_year.Items.Insert(0, New RadComboBoxItem("Select", ""))
End If
End If
objEntry_ml = Nothing
objEntry_bll = Nothing
ds = Nothing
End Sub
#End Region
#Region "Functions"
Public Function DrawGraph() As String
Try
Dim ds As DataSet
Dim dv As DataView
Dim dr As DataRowView
Dim sReturnMessage As String = ""
objEntry_ml = New ClsPF_BE
objEntry_bll = New ClsPF_BLL
strXML = "<chart palette='4' pieSliceDepth='30' pieRadius='120' CAPTION='Investment Pattern(In %)' bgcolor='#e5e5e5' outCnvBaseFont='verdana' outCnvBaseFontSize='11' showPercentageValues='1' bgAngle='360' showBorder='1' baseFont='Arial' baseFontSize='11' baseFontColor ='000000'>"
For Each item As GridDataItem In dg_InvPat.Items
Dim txt As Label = DirectCast(item.FindControl("lbl_revpat"), Label)
Dim aa As String = txt.Text
strXML = (strXML & ("<set label='" & (Server.HtmlEncode(item.Cells(4).Text) & ("' value='" & aa & "'/>"))))
Next
strXML = (strXML & "</chart>")
Return FusionCharts.RenderChartHTML("FusionCharts/Charts/Pie3D.swf", "", Server.UrlEncode(strXML.ToString), "Percentage", "500", "350", False)
Catch ex As Exception
divgraph1.Visible = False
lblmess.Text = "You have no rights to view this report"
lblmess.ForeColor = Drawing.Color.Red
lblhead.Text = ""
lbltotal.Text = ""
End Try
End Function
#End Region
Protected Sub b1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles b1.Click
Literal1.Text = DrawGraph()
pnlnum.Visible = True
divgraph1.Visible = True
End Sub
End Class
Here when i chnge the textbox in templatecolumn in radgrid, the corresponding value is stored in the label(GridTemplateColumn of Radgrid). That is written in javascript. But the corresponding fusion chart is not shown. When i debug, the new values(calculated by javascript) are not taken into account. Only the values which is being bound in the grid will be plotted in the fusion chart.
In DrawGraph() function i have used the label named as Revised pattern(GridTemplateColumn) value as <set label value. But the new value is not coming.
Eg. if i give 600 in Project Investment column, the corresponding percentage 42 is coming in Revised pattern(GridTemplateColumn). But the fusion chart is not changed.
How the problem can be solved?
ANYONE PLEASE HELP ME.........
I suggest you to go for the textbox instead label
Because textbox are server control and label have problem always getting values
like if you are using update panel or so.....
so textbox will be a best option to use

UserControl inside DataList

I have a UserControl inside DataList, I fill the controls inside the usercontrol according to the PrimeryKey of the DataList's data. At first load program behaves as expected but when user changes page index all the MessageID's returns 0, most probably value coming with
<%# Eval("id").toString()%> is lost. I dont want to hard code the usercontrol because i used it in many place in the project, it makes the code maintainable. How can i correct this behaviour? Thanks in advance.
My code is below:
<asp:DataList ID="DataList1" runat="server" Width="658px">
<ItemTemplate>
<table style="width: 100%;">
<tr>
<td style="font-weight: 700; color: #FF0000; font-size: medium; font-size: 10pt; font-family: Tahoma">
<%# Eval("hadding") +" ["+Eval("startTime")+" - "+Eval("endTime")+"]"%>
</td>
</tr>
<tr>
<td style="font-weight: 700; font-size: 10pt; font-family: Tahoma">
<%# Eval("location") %>
</td>
</tr>
<tr>
<td>
<uc1:MyUserControl ID="MyUserControl1" runat="server" MessageID='<%# Eval("id").toString()%>' />
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
<table>
<tr>
<td>
<asp:Button ID="btnfirst" runat="server" Font-Bold="true" Text="<<" Height="31px"
Width="43px" OnClick="btnfirst_Click" /></td>
<td>
<asp:Button ID="btnprevious" runat="server" Font-Bold="true" Text="<" Height="31px"
Width="43px" OnClick="btnprevious_Click" /></td>
<td>
<asp:Button ID="btnnext" runat="server" Font-Bold="true" Text=">" Height="31px"
Width="43px" OnClick="btnnext_Click" /></td>
<td>
<asp:Button ID="btnlast" runat="server" Font-Bold="true" Text=">>" Height="31px"
Width="43px" OnClick="btnlast_Click" /></td>
</tr>
</table>
and my user control:
Partial Class MyUserControl
Inherits System.Web.UI.UserControl
Private _messageID As Integer
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If (_messageID > 0) Then
Fill(_messageID)
End If
End Sub
Public Property MessageID As Integer
Get
Return _messageID
End Get
Set(value As Integer)
_messageID = value
End Set
End Property
Protected Sub Fill(messageID As Integer)
'Some code
End Sub
End Class
Difficult to answer without looking at the whole page lifecycle, but you may try to store the MessageId in your control's ViewState, like this :
Public Property MessageID As Integer
Get
If (Me.ViewState("VSMessageID") IsNot Nothing) Then
return CType(Me.ViewState("VSMessageID "), Integer)
else
return 0 // arbitrary value
End Get
Set(value As Integer)
Me.ViewState.Add("VSMessageID", value)
End Set
End Property
Then :
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If (MessageID > 0) Then
Fill(MessageID )
End If
End Sub
See http://msdn.microsoft.com/en-us/library/ms227551%28v=vs.85%29.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1
Sorry if bad VB.Net syntax
I solved the problem by changing the usercontrol as such:
Partial Class MyUserControl
Inherits System.Web.UI.UserControl
Public Property MessageID As Integer
Get
Return 0
End Get
Set(value As Integer)
Fill(value)
End Set
End Property
Protected Sub Fill(messageID As Integer)
'Some code
End Sub
End Class
As jbl said, this is because of the page lifecycle. OnPageIndexChange event of an ASPxDataview or on your custom PageIndexChange event for asp.net DataList, code work as such:
DataList (or ASPxDataview ) Load
UserControl Property setting
UserControl Load
PageIndexChange event
UserControl Load
UserControl Property setting
That's why on UserControl.Load Property is not set.

Resources