I am using nested repeaters with Dataset (not using Datatable) to retrieve information by passing parameters. So far I have bind the two repeaters clearly and everything is working fine.
Here the list of messages created by each user datawise(parameter passed) will be displayed, and there could be more than 50 messages created by each user daily. So now I want to do custom paging for each user.
But I am unable to proceed further, as the next, previous, back, first links are placed inside the child repeaters footer template and I couldn't access these links even by findcontrol method.
Example:
User1
No Msg Code
1 abcd Cl-6
2 some Cl-4
3 swedf Cl-3
4 sddf Cl-1
1,2,3,4,5 (Paging)
User2
No Msg Code
1 dgfv Cl-96
2 abcd Cl-4
3 sjuc Cl-31
4 liot Cl-1
1,2,3,4,5 (Paging)
In this ways goes for every user:
Public Sub CreateNestedRepeater()
Dim strSql_1 As String, strsql_2 As String
Dim strCon_1 As New SqlConnection
Dim strCon_2 As New SqlConnection
Dim ds As New DataSet()
frmDate = AMS.convertmmddyy(txtFromDate.Text)
toDate = AMS.convertmmddyy(txtToDate.Text)
strCon_1 = New SqlConnection(ConfigurationManager.ConnectionStrings("connectionString").ConnectionString)
strSql_1 = "select User_Login, User_Id from V_mst_UserMaster Where User_Flag = 1 and User_Type='CO'"
Dim daCust As New SqlDataAdapter(strSql_1, strCon_1)
daCust.Fill(ds, "RptCoord_Name")
WhereClause1 = "where MsgHdr_Id NOT IN (Select a.MsgHdr_Id from V_AMS_GetSentMsg as a Join V_AMS_GetSentMsg as b " _
& "on a.MsgHdr_Id = b.MsgHdr_PrevMsgId) and MsgHdr_Date >= '" & frmDate & "' and MsgHdr_Date <= '" & toDate & _
"'AND MsgHdr_MsgFlag='I' and MsgHdr_AckReq <> 'N'"
OrderBy = "order by MsgHdr_Date asc"
strCon_2 = New SqlConnection(ConfigurationManager.ConnectionStrings("conn_Ind_AKK_TRAN").ConnectionString)
strsql_2 = "select User_Login,MsgHdr_Date, Client_Code, MsgHdr_RefNo, MsgType_Name, MsgHdr_Subject " _
& " from V_AMS_GetSentMsg " & WhereClause1 & OrderBy
Dim daOrders As New SqlDataAdapter(strsql_2, strCon_2)
daOrders.Fill(ds, "RptCd_Record")
Dim rel As New DataRelation("CrdRelation", ds.Tables("RptCoord_Name").Columns("User_Login"), ds.Tables("RptCd_Record").Columns("User_Login"), False)
ds.Relations.Add(rel)
rel.Nested = True
Rep1.DataSource = ds.Tables("RptCoord_Name").DefaultView
Rep1.DataBind()
strCon_1.Close()
strCon_2.Close()
End Sub
Protected Sub Rep1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles Rep1.ItemCommand
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
DirectCast(e.Item.FindControl("Rep2"), Repeater).DataSource = DirectCast(e.Item.DataItem, DataRowView).CreateChildView("CrdRelation")
DirectCast(e.Item.FindControl("Rep2"), Repeater).DataBind()
End If
End Sub
Protected Sub Pagging(ByVal index As Integer)
Dim PDS As New PagedDataSource
PDS.DataSource = ds.Tables("RptCoord_Name").DefaultView
PDS.CurrentPageIndex = index
PDS.AllowPaging = True
PDS.PageSize = 4
Dim rep2 As Repeater = CType(e
rep2.DataSource = PDS
Rep2.DataBind()
Dim ddl As DropDownList = DirectCast(rep2.Controls(rep2.Controls.Count - 1).FindControl("PageCount"), DropDownList)
If ddl IsNot Nothing Then
For i As Integer = 1 To PDS.PageCount - 1
ddl.Items.Add(i.ToString())
Next
End If
End Sub
Public Sub PageIndex(ByVal sender As Object, ByVal e As EventArgs)
Dim ddl As DropDownList = DirectCast(rep2.Controls(rep2.Controls.Count - 1).FindControl("PageCount"), DropDownList)
Pagging(Integer.Parse(ddl.SelectedItem.Text) - 1)
End Sub
XML:
<asp:Repeater id="Rep1" runat="server" OnItemCommand="Rep1_ItemCommand" EnableViewState = "false" >
<ItemTemplate>
<table width="100%" border="0.8" cellpadding="0" cellspacing="0" CssClass="bodytext" >
<tr><td align="center" class="RepHeader" >
Incoming Messages - Pending Ack for
<%#getUser(DataBinder.Eval(Container.DataItem, "User_Login"))%> from <%= txtFromDate.Text %>
to <%=txtToDate.Text%>
<%-- OnItemDataBound="Rep2_ItemDataBound" --%>
<asp:Repeater id="Rep2" runat="server" datasource='<%#(Container.DataItem).Row.GetChildRows("CrdRelation") %>' >
<HeaderTemplate>
<table border="1" width="100%" >
<tr class="RepHeader" >
<td>Msg Date</td><td>CL Code</td><td>INCRefNo</td><td>Contents</td><td>Subject</td></tr></HeaderTemplate><ItemTemplate>
<tr class="RrpList">
<td><%#getdate(CType(Container.DataItem, System.Data.DataRow)("MsgHdr_Date"))%> </td>
<td><%#CType(Container.DataItem, System.Data.DataRow)("Client_Code")%> </td>
<td><asp:LinkButton ID="lnkRef" runat="server"></asp:LinkButton>
<a id="hrefRefNo" runat="server" href="#" class="Link" >
<%#CType(Container.DataItem, System.Data.DataRow)("MsgHdr_RefNo")%></a></td>
<td><%#CType(Container.DataItem, System.Data.DataRow)("MsgType_Name")%> </td>
<td><%#CType(Container.DataItem, System.Data.DataRow)("MsgHdr_Subject")%> </td>
</tr>
</ItemTemplate>
<FooterTemplate>
<%--Starts Here - (Paging for Pending Nested Repeaters) --%>
<tr align="center" class = "RepHeader">
<td colspan="5">
<asp:LinkButton ID="lnkFirst" runat="server" ForeColor="Black" Text="First" >
</asp:LinkButton>
<asp:LinkButton ID="lnkPrevious" runat="server" ForeColor="Black" Text="Previous" >
</asp:LinkButton> Now Showing Page
<asp:DropDownList ID="ddlpageNumbers" runat="server" AutoPostBack="true" >
</asp:DropDownList> of <asp:Label ID="lblTotalPages" runat="server"> </asp:Label>
Pages.
<asp:LinkButton ID="lnkNext" runat="server" ForeColor="Black" Text="Next" >
</asp:LinkButton>
<asp:LinkButton ID="lnkLast" runat="server" ForeColor="Black" Text="Last" >
</asp:LinkButton>
</td> </tr>
<%--Ends Here (Paging for Pending Nested Repeaters)--%>
</td></tr>
<br />
</table>
</FooterTemplate>
</asp:Repeater>
</ItemTemplate>
<SeparatorTemplate><br /><br /></SeparatorTemplate>
</asp:Repeater>
I couldn't understand how to do paging.
You shroud read about it:
http://idunno.org/archive/2004/10/30/145.aspx
http://support.microsoft.com/kb/306154
Related
I developed the compose message from email,
I attaching the files then i have selecting the combo box item its deleting the attachment files.
Here my ASP Code:
<asp:UpdatePanel ID="updatepanel" runat="server">
<ContentTemplate>
<tr>
<td valign="top">
<asp:Label ID="lblfile_name" runat="server" CssClass="labels">Upload File</asp:Label>
</td>
<td>
<div style="overflow-y: scroll; z-index: auto; height: 60px;">
<asp:FileUpload ID="FileUpload1" runat="server" CssClass="multi" Visible="true" />
</div>
</td>
</tr>
</ContentTemplate>
</asp:UpdatePanel>
<tr>
<td>
<telerik:RadComboBox EmptyMessage="----- Select -----" ID="cboTemplate" runat="server" Skin="WebBlue" AutoPostBack="true">
</telerik:RadComboBox>
</td>
</tr>
Here VB. NET CODE
Private Sub cboTemplate_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboTemplate.SelectedIndexChanged
If cboTemplate.SelectedValue = "--Select--" Then
lblErrMsg.Text = objcmnfunctions.GetErrMsg("B2B_WAR_110")
SetFocus(anc_err)
Exit Sub
End If
objdbconn.OpenConn()
msSQL = " Select mailtemplate_gid, template_name, template_content " & _
" from crm_trn_tmailtemplates " & _
" where mailtemplate_gid = '" & cboTemplate.SelectedValue & "'"
objOdbcDataReader = objdbconn.GetDataReader(msSQL)
If objOdbcDataReader.HasRows = True Then
objOdbcDataReader.Read()
radmailcontent.Content = objOdbcDataReader.Item("template_content").ToString
End If
objOdbcDataReader.Close()
objdbconn.CloseConn()
End Sub
Store the value of FileUpload1 to Session Object
If Session("FileUpload1") Is Nothing AndAlso FileUpload1.HasFile Then
Session("FileUpload1") = FileUpload1
ElseIf Session("FileUpload1") IsNot Nothing AndAlso (Not FileUpload1.HasFile) Then
FileUpload1 = DirectCast(Session("FileUpload1"), FileUpload)
ElseIf FileUpload1.HasFile Then
Session("FileUpload1") = FileUpload1
End If
The reason the dropdown is clearing the value from Upload is because it is set to AutoPostBack="true"
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
I have two repeaters, one nested in the other. I'm outputting a list of course titles in the parent repeater and the dates of those courses in the child repeater. This part is working fine. But, not all the course titles necessarily have dates available at any given time, so I want to be able to put a message up under each Course title that currently has no dates saying to check back regularly, blah, blah, blah. I've put the label in the footer template of the nested repeater with visibility=false and am trying to set the visibility=true at the appropriate time in the ItemDataBound Sub. Unfortunately, this is not working. I'm not getting any errors, the label just isn't showing up. I'm really hoping someone can help me out with my code or suggest an alternate way to do this. I'm kinda new to asp.net(VB) and am still struggling a bit. I've never tried nesting repeaters before. Here is my code:
.aspx
<asp:Repeater ID="rptTech" runat="server" >
<HeaderTemplate>
<table class="tableCourses">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<strong><asp:Label runat="server" ID="lblCourseName" Text='<%# Eval("CourseName") %>'></asp:Label></strong>
<br />
<asp:Label runat="server" ID="lblCourseSummary" Text='<%# Eval("Summary") %>'></asp:Label>
<br />
<asp:HyperLink ID="hpCourseMaterial" Visible='<%# CheckCourseMaterial(Eval("CourseMaterial")) %>' NavigateUrl='<%# "/files/Portal_Course_Material/" & Eval("CourseMaterial")%>' Text="Download Course Material" runat="server"></asp:HyperLink>
</td>
</tr>
<tr>
<td>
<asp:Repeater ID="rptTechDates" DataSource='<%#Eval("relCourses") %>' runat="server" >
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<strong><asp:Label runat="server" ID="lblDate" Text='<%# CDate(Eval("dteDate")).ToString("dd/MM/yyyy") %>'></asp:Label></strong><br />
<asp:Label runat="server" ID="dteTime" Text='<%# "Time: " & CDate(Eval("dteTime2")).ToString("HH:mm") & " EST" %>'></asp:Label><br />
<asp:HyperLink ID="Register" NavigateUrl='<%# "/Test.aspx?intMeetingID2=" & Eval("pkWebinarID")%>' Text="Register" runat="server"></asp:HyperLink>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr>
<td>
<asp:Label ID="lblNoCourses" Text="There are no course dates available at this time. Please check back regularly to see any updates." runat="server" Visible="False"></asp:Label>
</td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
And Codebehind:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim curDate As Date = CDate(Now)
'Create the connection
Dim connstring As String
connstring = ConfigurationManager.ConnectionStrings("LPISQLConn").ConnectionString
Using conn As New SqlConnection(connstring)
Dim cmd As New SqlCommand("SELECT foo1, foo2, foo3 FROM tblFoo", conn)
cmd.CommandType = CommandType.Text
Dim ad As New SqlDataAdapter(cmd)
Dim ds As New DataSet()
ad.Fill(ds)
ds.Relations.Add(New DataRelation("relCourses", ds.Tables(0).Columns("fkcrsID"), ds.Tables(1).Columns("webinarID"), False))
rptTech.DataSource = ds.Tables(0)
rptTech.DataBind()
End Using
End Sub
Protected Sub rptTech_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
Dim drv As DataRowView = TryCast(e.Item.DataItem, DataRowView)
Dim rptTechDates As Repeater = TryCast(e.Item.FindControl("rptTechDates"), Repeater)
rptTechDates.DataSource = drv.CreateChildView("relCourses")
If rptTechDates.Items.Count < 1 And rptTechDates IsNot Nothing Then
If e.Item.ItemType = ListItemType.Footer Then
Dim lblNoCourses As Label = TryCast(e.Item.FindControl("lblNoCourses"), Label)
If lblNoCourses IsNot Nothing Then
lblNoCourses.Visible = True
End If
End If
Else
rptTechDates.DataBind()
End If
End If
End Sub
I would do the following:
Change your ItemDataBoundEvent for the parent repeater to:
Protected Sub rptTech_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
Dim drv As DataRowView = TryCast(e.Item.DataItem, DataRowView)
Dim rptTechDates As Repeater = TryCast(e.Item.FindControl("rptTechDates"), Repeater)
rptTechDates.DataSource = drv.CreateChildView("relCourses")
rptTechDates.DataBind()
End If
End Sub
Add this to the markup of your child repeater:
OnItemDataBound="rptTechDates_ItemDataBound"
Now add this:
Protected Sub rptTechDates_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs)
If e.Item.ItemType = ListItemType.Footer Then
If DirectCast(DirectCast(e.Item.NamingContainer, Repeater).DataSource, DataTable).Rows.Count = 0 Then
DirectCast(e.Item.FindControl("lblNoCourses"), Label).Visible = True
End If
End If
So, if the number of rows in the child repeater's datasource is 0, then show the label.
EDIT After comment from OP
Protected Sub rptTechDates_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs)
If e.Item.ItemType = ListItemType.Footer Then
If DirectCast(DirectCast(e.Item.NamingContainer, Repeater).DataSource, DataView).Count = 0 Then
DirectCast(e.Item.FindControl("lblNoCourses"), Label).Visible = True
End If
End If
You want to search rptTechDates repeater for the lblNoCourses control. The e.Item.FindControl("lblNoCourses") is searching the rptTech repeater which doesn't exist. See this question to search the control in the rptTechDates footer.
Also, you'll want to call Databind() on the repeater after setting it's DataSource
rptTechDates.DataSource = drv.CreateChildView("relCourses")
rptTechDates.Databind()
I am working on an aspx site that lets an admin-level user fill out a form with potential member data. Once the form is filled out, the user will click submit and the data will go off to different tables. One part of the form that is stumping me involves filling out three textboxes (txtFirstName, txtLastName, txtGrade). I have a button (btnAddStudent), that, when clicked, should add the information from the textboxes to a table-like display area. I am trying to use a gridview, but there is nothing to bind it to. There is no memberID number to load a blank record from the Student table (which is a many-to-one relation to Member table). The member record is what this form is creating, and the student data will be added to the Student table when the Submit button is clicked.
I am currently working with the code found in the reply here. But when I click the "Add Student" button, I get a new blank row, but my textbox values are not inputted in the gridview.
Can this work, or do I need to look at using a table and adding rows of textboxes dynamically?
Here is relevant source code:
<tr>
<td class="style8">
<asp:Label ID="Label18" runat="server" Text="Chidren:" Font-Bold="True" Font- Underline="True" Font-Names="Tahoma"></asp:Label>
</td>
</tr>
<tr>
<td class="style8">
<asp:Label ID="Label19" runat="server" Text="First Name:"></asp:Label>
</td>
<td class="style7">
<asp:TextBox ID="txtChildFirstName" runat="server" CssClass="textbox"></asp:TextBox>
</td>
<td class="">
<asp:Label ID="Label20" runat="server" Text="Last Name:"></asp:Label>
</td>
<td class="style6">
<asp:TextBox ID="txtChildLastName" runat="server" CssClass="textbox"></asp:TextBox>
</td>
<td class="style5" align="right">
<asp:Label ID="Label21" runat="server" Text="Grade:"></asp:Label>
</td>
<td class="style4">
<asp:TextBox ID="txtGrade" runat="server" Width="52px" CssClass="textbox"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnAddChild" runat="server" Text="Add Child" OnClick="btnAddChild_Click" />
</td>
</tr>
<tr>
<td valign="top" class="style8">
<asp:Label ID="Label22" runat="server" Text="Student List:"></asp:Label>
</td>
<td colspan="3">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="gvStudentList" runat="server" AutoGenerateColumns="False"
PageSize="5" Height="42px">
<AlternatingRowStyle BackColor="#E0E0E0" />
<Columns>
<asp:BoundField AccessibleHeaderText="FirstName" HeaderText="First Name" />
<asp:BoundField AccessibleHeaderText="LastName" HeaderText="Last Name" />
<asp:BoundField AccessibleHeaderText="Grade" HeaderText="Grade" />
</Columns>
<HeaderStyle BackColor="#CCCCCC" Height="25px" />
<RowStyle Height="22px" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
And the Code Behind:
'A method that will BIND the GridView based on the TextBox
'values and retain its values on post backs.
Private Sub BindGrid(rowcount As Integer)
Dim dt As New DataTable()
Dim dr As DataRow
dt.Columns.Add(New System.Data.DataColumn("FirstName", GetType([String])))
dt.Columns.Add(New System.Data.DataColumn("LastName", GetType([String])))
dt.Columns.Add(New System.Data.DataColumn("Grade", GetType([String])))
If ViewState("CurrentData") IsNot Nothing Then
For i As Integer = 0 To rowcount
dt = DirectCast(ViewState("CurrentData"), DataTable)
If dt.Rows.Count > 0 Then
dr = dt.NewRow()
dr(0) = dt.Rows(0)(0).ToString()
End If
Next
dr = dt.NewRow()
dr(0) = txtChildFirstName.Text
dr(1) = txtChildLastName.Text
dr(2) = txtGrade.Text
dt.Rows.Add(dr)
Else
dr = dt.NewRow()
dr(0) = txtChildFirstName.Text
dr(1) = txtChildLastName.Text
dr(2) = txtGrade.Text
dt.Rows.Add(dr)
End If
' If ViewState has a data then use the value as the DataSource
If ViewState("CurrentData") IsNot Nothing Then
gvStudentList.DataSource = DirectCast(ViewState("CurrentData"), DataTable)
gvStudentList.DataBind()
Else
' Bind GridView with the initial data assocaited in the DataTable
gvStudentList.DataSource = dt
gvStudentList.DataBind()
End If
' Store the DataTable in ViewState to retain the values
ViewState("CurrentData") = dt
End Sub
Protected Sub btnAddChild_Click(sender As Object, e As EventArgs) Handles btnAddChild.Click
' Check if the ViewState has a data assoiciated within it. If
If ViewState("CurrentData") IsNot Nothing Then
Dim dt As DataTable = DirectCast(ViewState("CurrentData"), DataTable)
Dim count As Integer = dt.Rows.Count
BindGrid(count)
Else
BindGrid(1)
End If
txtChildFirstName.Text = String.Empty
txtChildLastName.Text = String.Empty
txtGrade.Text = String.Empty
txtChildFirstName.Focus()
End Sub
With "BindGrid()" being called in the Page_Load event. (And yes, I have ScriptManager)
Try to use
Session("CurrentData") = dt on your BindGrid()
Then Create Method that just refreshes the grid after postback:
Private Sub RefreshGrid()
{
If ViewState("CurrentData") IsNot Nothing Then
gvStudentList.DataSource = DirectCast(Session("CurrentData"), DataTable)
gvStudentList.DataBind()
Else
gvStudentList.DataSource = null;
gvStudentList.DataBind()
EndIf
}
On your page load just call:
If IsPostBack Then
Return
End If
RefreshGrid()
Regards
As this is my first project, I really do not have much idea to debug this. I have a listview. I am writing code manually to populate listview. As the listview is very large, I have a search button where user enters a search string. I am trying to build a sql string from here and populate the listview. Everything works fine but when I click on next page, it does not include the search string. I think it is just populating the 2nd page without the search criteria. If I remove the data pager control, it works fine. I am not able to put proper code datapger_PagePropertiesChanging. I appreciate if someone can help me with this.
Here is my list view markup:
<asp:ListView ID="lvContractors" runat="server" OnPagePropertiesChanging="lvContractors_PagePropertiesChanging">
<LayoutTemplate>
<div class="ListViewGrid">
<table class="tblpadding">
<tr>
<th class="HeaderStyle">
Contractor Number
</th>
<th class="HeaderStyle">
First Name
</th>
<th class="HeaderStyle">
Last Name
</th>
<th class="HeaderStyle">
View
</th>
<th class="HeaderStyle">
Edit
</th>
</tr>
<tbody><asp:PlaceHolder runat="server" ID="itemPlaceholder" /></tbody>
</table>
</div> <!-- End of ListViewGrid -->
</LayoutTemplate>
<ItemSeparatorTemplate> <td> <hr /> </td>
</ItemSeparatorTemplate>
<ItemTemplate>
<div >
<tr>
<td class="RowStyle"><%#Eval("ContractorNumber")%></td>
<td class="RowStyle"><%#Eval("FirstName")%></td>
<td class="RowStyle"><%#Eval("LastName")%></td>
<td class="RowStyle">
<asp:HyperLink ID="lnkView" runat="server" CssClass="link"
NavigateUrl='<%# "ContractorEdit.aspx?ID=" + Eval("ContractorNumber") + "&Mode=" + "CV" %>'
Target="_blank" Text="View" />
</td>
<td class="RowStyle">
<asp:HyperLink ID="lnkEdit" runat="server" CssClass="link"
NavigateUrl= '<%# "ContractorEdit.aspx?ID=" + Eval("ContractorNumber") + "&Mode=" + "CE" %>'
Text="Edit"> </asp:HyperLink>
</tr>
</div>
</ItemTemplate>
<AlternatingItemTemplate>
<div>
<tr>
<td class="AlternatingRowStyle"><%#Eval("ContractorNumber")%></td>
<td class="AlternatingRowStyle"><%#Eval("FirstName")%></td>
<td class="AlternatingRowStyle"><%#Eval("LastName")%></td>
<td class="AlternatingRowStyle">
<asp:HyperLink ID="lnkView" runat="server" CssClass="link"
NavigateUrl='<%# "Contractor.aspx?ID=" + Eval("ContractorNumber")%>'
Target="_blank" Text="View" />
</td>
<td class="AlternatingRowStyle">
<asp:HyperLink ID="lnkEdit" runat="server" CssClass="link"
NavigateUrl= '<%# "ContractorEdit.aspx?ID=" + Eval("ContractorNumber") + "&Mode=" + "CE" %>'
Text="Edit"> </asp:HyperLink>
</tr>
</div>
</AlternatingItemTemplate>
<ItemSeparatorTemplate>
<tr>
<td colspan="5" class="itemseparator"></td>
</tr>
</ItemSeparatorTemplate>
</asp:ListView>
<div class="pager">
<asp:DataPager PageSize="20" ID="DataPagerContractor" runat="server" PagedControlID="lvContractors"
NextPreviousButtonCssClass="PrevNext"
CurrentPageLabelCssClass="CurrentPage"
NumericButtonCssClass="PageNumber">
<fields>
<asp:NumericPagerField
PreviousPageText="< Prev"
NextPageText="Next >"
ButtonCount="10"
NextPreviousButtonCssClass="PrevNext"
CurrentPageLabelCssClass="CurrentPage"
NumericButtonCssClass="PageNumber" />
</fields>
</asp:DataPager>
</div>
</div> Code behind this: Partial Class Contractor
Inherits System.Web.UI.Page
Private txtKeywordSearchWhereClause As String = ""
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Session("Clicked") = "Contractor"
End If
If Not DBNull.Value.Equals(txtKeywordSearchWhereClause) Then
LoadContractors(txtKeywordSearchWhereClause)
Else
LoadContractors("")
End If
End Sub
Private Sub LoadContractors(ByVal strSearch As String)
Dim strConn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("Conn").ConnectionString)
strConn.Open()
Dim sql As String = "SELECT * FROM tblContractor1"
If Not strSearch = "" Then
sql = sql & strSearch
sql = sql & " ORDER BY LastName"
End If
Dim da As SqlDataAdapter = New SqlDataAdapter(sql, strConn)
Dim dt As DataTable = New DataTable()
da.Fill(dt)
lvContractors.DataSource = dt
lvContractors.DataBind()
End Sub
Protected Sub buttonAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles buttonAdd.Click
Response.Redirect("ContractorEdit.aspx", False)
End Sub
Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
' Keyword Search
Dim txtKeywordSearch As String = txtSearch.Text
Dim txtWhereClause As String = ""
If txtKeywordSearch.Trim() <> "" Then
txtWhereClause = " WHERE FirstName LIKE '%" + txtKeywordSearch + "%'"
txtWhereClause = txtWhereClause + " OR LastName LIKE '%" + txtKeywordSearch + "%'"
txtWhereClause = txtWhereClause + " OR ContractorNumber LIKE '%" + txtKeywordSearch + "%'"
txtKeywordSearchWhereClause = txtWhereClause
End If
LoadContractors(txtKeywordSearchWhereClause)
End Sub
Protected Sub lvContractors_PagePropertiesChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.PagePropertiesChangingEventArgs) Handles lvContractors.PagePropertiesChanging
DataPagerContractor.SetPageProperties(e.StartRowIndex, e.MaximumRows, False)
'rebind List View
If Not DBNull.Value.Equals(txtKeywordSearchWhereClause) Then
LoadContractors(txtKeywordSearchWhereClause)
Else
LoadContractors("")
End If
End Sub
End Class
Sorry to say, but this is not possible with the datapager (at least in ASP.Net 3.5).
The only solution is to write your own pager from scratch as the only querystring parameter the datapager can pass is the page number.