I have an ASP.Net Repeater I want to use to show From and Text from a dataset and I want to add it programmically. I have all the data in a dataset and can use that and I have verified the correct number for datarows when it loads so the data is their it is just not showing. What have I missed?.
Dim data As New Data
Dim ds As New DataSet
ds = data.LOADALL()
Dim drMsg() As DataRow = ds.Tables("MESSAGESYSTEM").Select("TOID='101'")
repeatMessages.DatagSource = drMsg
Now on the html side I have:
<asp:Repeater ID="repeatMessages" runat="server" >
<HeaderTemplate>
<table>
<tr>
<th>From</th>
<th>Sublect</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td bgcolor="#CCFFCC">
<asp:Label runat="server" ID="Label1" text='<%# Eval("FROMID") %>' />
</td>
<td bgcolor="#CCFFCC">
<asp:Label runat="server" ID="Label2" text='<%# Eval("MESSAGETEXT") %>' />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
How can I fix this code to show the data in the Message table?
Try calling repeatMessages.DataBind(). All you are doing is assigning the source but you haven't told the program to do something with the data.
Related
I am using a listview to display datas from 3 tables in mysql.
My tables are,
theatredet(theaterid,theatername,locationid)
location(locationid,locationname)
screendet(screenname,theaterid,seatsavailable)
I want to display datas from screendet on the basis of theaterid from the table theatredet,i can only able to disply single data from screendet,there are multiple datas on that table with respect of theaterid.
My query is,
string query = "SELECT `theatredetails`.*,`Location`.`LocationName`,
`screendetails`.`ScreenName`,`screendetails`.`SeatsAvailable`
FROM `theatredetails`INNER JOIN `screendetails`
ON `screendetails`.`TheatreDetailsId` = `theatredetails`.`TheatreDetailsId`
INNER JOIN `location` ON `location`.`LocationId`=`theatredetails`.`LocationId`;";
My aspx
<asp:TextBox ID="TextBox6" runat="server" Text='<%#Bind("ScreenName") %>'></asp:TextBox>
<asp:TextBox ID="TextBox7" runat="server" Text='<%#Bind("SeatsAvailable") %>'></asp:TextBox>
Assuming you have already tested your query on MySql and it is returning intended number of rows.
You can populate your listview using the following code (I am using SqlDataSource to bind the ListView, you can use any other method)
<asp:ListView ID="lstviewScreens" runat="server" DataSourceID="ScreensSqlDataSource" >
<LayoutTemplate>
<table id="itemPlaceholderContainer" runat="server" >
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr style="background-color: #E0FFFF;">
<td>
<strong>Theater Name:</strong><asp:Label ID="lblTheaterName" runat="server" Text='<%# Eval("theatername") %>' />
<br />
<strong>Screen Name:</strong><asp:Label ID="lblScreenName" runat="server" Text='<%# Eval("ScreenName") %>' />
<br />
<strong>Seats Available</strong><asp:Label ID="lblSeatsAvailable" runat="server" Text='<%# Eval("SeatsAvailable") %>' />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="ScreensSqlDataSource" runat="server"
ConnectionString="Your connection String"
SelectCommand="SELECT theatredetails.*,Location.LocationName,
screendetails.ScreenName,screendetails.SeatsAvailable
FROM theatredetails INNER JOIN screendetails
ON screendetails.TheatreDetailsId = theatredetails.TheatreDetailsId
INNER JOIN location ON location.LocationId=theatredetails.LocationId">
</asp:SqlDataSource>
This will output your data in tabular format, however you can customize LayoutTemplate to change the generated html, even you can use GroupTemplate to group the data.
I bind the repeater with SqlDataReader but I want when repater has no row than a blank row is added in ItedDataBound Event
1- First Create A DataTable Object to hold your data
2- Check for the Number of Rows in the DataTable if Zero then Add Empty DataRow Object To DataTable
3- Bind Your Repeater to the DataTable Instead to Datareader Object
if(dt.Rows.Count==0)
{
DataRow dr=dt.NewRow();
dt.Rows.Add(dr);
}
rptDemo.DataSource=dt;
rptDemo.DataBind();
Try this.
Place label in the footer of repeater in FooterTemplate and by default set visible to false and in ItemDataBound set to visible=true when item count is 0 or less than 1.
<asp:Repeater ID="rptDemo" runat="server"
OnItemDataBound="rptDemo_ItemDataBound">
<ItemTemplate>
.......
</ItemTemplate>
<FooterTemplate>
<%-- Label used for no data available --%>
<asp:Label ID="lblMsg" runat="server" CssClass="errMsg" Text="Sorry, no item is there to show." Visible="false">
</asp:Label>
</FooterTemplate>
protected void rptDemo_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (rptDemo.Items.Count < 1)
{
if (e.Item.ItemType == ListItemType.Footer)
{
Label lblFooter = (Label)e.Item.FindControl("lblMsg");
lblFooter.Visible = true;
}
}
}
Hope this helps!
My requirement was to show add row inside repeater. Me included a blank row as the last item by doing a small checking, in all other rows, blank row made hidden.
Used
<%# (((IList)((Repeater)Container.Parent).DataSource).Count).ToString() == (Container.ItemIndex + 1).ToString() %>
checking to decide whether to show or hide blank row.
Full code of view:
<table>
<asp:Repeater ID="repeater1" OnItemCommand="repeater_user_Itemcommand" runat="server">
<HeaderTemplate>
<tr>
<td>
Name
</td>
<td>
Email
</td>
<td>
Delete
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label ID="lblName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"Name") %>'></asp:Label>
</td>
<td>
<asp:Label ID="lblEmail" runat="server" Text='<%# Eval("Email") %>'></asp:Label>
</td>
<td>
<asp:LinkButton ID="btnDelete" runat="server" CommandArgument='<%# Eval("ID") %>'
CommandName="delete">Delete</asp:LinkButton>
</td>
</tr>
<tr id="Tr1" runat="server" visible='<%# (((IList)((Repeater)Container.Parent).DataSource).Count).ToString() == (Container.ItemIndex + 1).ToString() %>'>
<td>
<asp:TextBox ID="txtName_add" runat="server" Enabled="True" Text='' Visible="false"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtEmail_add" runat="server" Text='' Visible="false"></asp:TextBox>
</td>
<td>
<asp:LinkButton ID="btnShowAdd" runat="server" CommandName="add">Add</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
I have an ASP.NET GridView. Now I am adding the SortExpression property tothe <TemplateField> tags, to make specific columns sortable.
Now, one of the columns has some markup content to be added in the header. The problem is, SortExpression does not work if there is a <HeaderTemplate> tag in a <TemplateField>, you have to put it inside the HeaderText property of <TemplateField>. But, all the HTML content does not work properly if I dump it inside the HeaderText property.
<asp:TemplateField SortExpression="FK_TesterID" ItemStyle-Width="300px" FooterStyle-Width="300px" ItemStyle-HorizontalAlign="Center" FooterStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">
<HeaderTemplate>
<table width="100%">
<tr>
<td align="center">
Tester
</td>
</tr>
<tr>
<td>
<asp:DropDownList ID="cmbTestersHeader" ClientIDMode="Static" runat="server" Width="300px" DataSource='<%# PopulateTesterNames() %>' DataTextField="FullName" DataValueField = "PK_ID" Visible="false" AutoPostBack="true" OnSelectedIndexChanged="cmbTestersHeader_SelectedIndexChanged" ToolTip="Bulk Assign Testers !" ></asp:DropDownList>
</td>
</tr>
</table>
</HeaderTemplate>
So you can see, if I put the entire <HeaderTemplate> property inside a headertext, it doesn't work.
But I want to have both functionalities. Can anyone help?
Then you need to provide a control in your HeaderTemplate with CommandName="Sort", for example a LinkButton.
<HeaderTemplate>
<table width="100%">
<tr>
<td align="center">
<asp:LinkButton ID="LbSort" runat="server" CommandName="Sort" Text="Sort" />
</td>
</tr>
<tr>
<td>
<asp:DropDownList ID="cmbTestersHeader" ClientIDMode="Static" runat="server" Width="300px"
DataSource='<%# PopulateTesterNames() %>' DataTextField="FullName" DataValueField="PK_ID"
Visible="false" AutoPostBack="true" OnSelectedIndexChanged="cmbTestersHeader_SelectedIndexChanged"
ToolTip="Bulk Assign Testers !">
</asp:DropDownList>
</td>
</tr>
</table>
</HeaderTemplate>
This is a quite old thread I have stumbled over while trying to solve exactly that described problem but the solution provided here didn't worked for me. If you have a Sorting method defined for the GridView then
<asp:LinkButton ID="LbSort" runat="server" CommandName="Sort" Text="Sort" />
will call that method
protected void GridView_Sorting(object sender, GridViewSortEventArgs e)
{
dt.DefaultView.Sort = e.SortExpression;
but e.SortExpression will be null and no sorting is happening. You have to first pass the Column's name through the CommandArgument of the LinkButton. Only then it worked in my case!
<asp:LinkButton ID="LbSort" runat="server" CommandName="Sort" CommandArgument="ColumnName" Text="Sort" />
I have a HTML table that is built with a repeater. Sometimes the table has 5 rows, sometimes it has 8 rows.
It was easy to add the header rows.
<asp:PlaceHolder runat="server" ID="additionalHeaderColumns" />
In code behind I added controls (htmlheadercells) to the contentholder:
Dim tableHeaderCell As New TableHeaderCell()
tableHeaderCell.Text = "Test"
additionalHeaderColumns.Controls.Add(tableHeaderCell)
When I try to do the same in the databound event for each row I get an errormessage that tells that its not possible to put asp:PlaceHolder inside the row. it expects tablecells.
Anybody have a solution how to expand number of columns in a repeater?
if i understand your problem as "add columns to the table depending on some data":
<asp:Repeater ID="outerRepeater" runat="server">
<HeaderTemplate>
<table>
<tr>
<td>fixedHeaderCell</td>
<td>fixedHeaderCell2</td>
<asp:Repeater ID="innerColumnRepeater" runat="server" DataSource='<%# someFreakySourceFromYourPageOrOuterRepeater %>'>
<ItemTemplate>
<td>dynHeaderCell</td>
</ItemTemplate>
</asp:Repeater>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>fixedContentCell</td>
<td>fixedContentCell2</td>
<asp:Repeater ID="innerColumnRepeater" runat="server" DataSource='<%# someFreakySourceFromYourPageOrOuterRepeater %>'>
<ItemTemplate>
<td>dynContentCell</td>
</ItemTemplate>
</asp:Repeater>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
look further for nested repeater, there is a lot of content here.
I'm just beinning basic data driven ASP.NET webforms design. I have the first part of a form working, but I don't know what to do next.
Please see this screenshot of what I have created so far: http://www.twitpic.com/2gnmr
I need help knowing what kind of HTML element to use in the master list, and what event/trigger on that element to use to fire off the "get child records for this selected item" sequence?
Also, is a ListView even the correct way to present the master list? At this time, I'm not trying to provide any editing features; I'll get to that later, I guess.
Should I use some other ASP.NET data control rather than hand-coding a listview like I am doing?
I don't want to see an actual "Select" link item beside each Customer Name (that looks goofy). I want the Customer Name to be the link to click on.
So, you can see in my code below that I have a ListView to present a list of CustomersWithOpenOrders. But, it's just a static list, so how do I make the Company Name label clickable, and what else will I need to make it fire back to some code-behind to fetch the child records. I already have a code-behind method to get child records for a passed-in CustomerNumber into a DataTable, and I think I would know how to bind that to a grid or listview for child records, but I do not know how to pass the CustomerNumber from the master ListView to the method from the UI form.
<asp:ListView ID="ListView1" runat="server">
<LayoutTemplate>
<table cellpadding="2" border="0" ID="tbl1" runat="server">
<tr id="Tr1" runat="server" class="lvHeader">
<th id="Th1" runat="server">Customer</th>
</tr>
<tr runat="server" id="itemPlaceholder" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr id="Tr2" runat="server">
<td>
<asp:Label ID="label2" class="FirstLine" runat="server" Text='<%# Eval("company") %>' />
<br />
<div class="SecondLine">
<asp:Label ID="labelCustNo" runat="server" Text='<%# Eval("custno") %>'/>
<asp:Label runat="server" Text='Ph: '></asp:Label>
<asp:Label ID="label3" runat="server" Text='<% # Eval("phone") %>' />
</div>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
I personally haven't found a case where the ListView can't solve my needs. If you want to create a customer selection style list you can use a link button for binding.
<asp:ListView runat="server" id="CustomersList" ItemCommand="CustomersList_ItemCommand">
<LayoutTemplate>
<table cellpadding="2" border="0" ID="tbl1" runat="server">
<tr id="Tr1" runat="server" class="lvHeader">
<th id="Th1" runat="server">Customer</th>
</tr>
<tr runat="server" id="itemPlaceholder" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr id="Tr2" runat="server">
<td>
<asp:LinkButton ID="link1" class="FirstLine" runat="server" Text='<%# Eval("company") %>' CommandName="Select" />
<br />
<div class="SecondLine">
<asp:Label ID="labelCustNo" runat="server" Text='<%# Eval("custno") %>'/>
<asp:Label runat="server" Text='Ph: '></asp:Label>
<asp:Label ID="label3" runat="server" Text='<% # Eval("phone") %>' />
</div>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
<asp:ListView runat="server" ID="OrderList">
<!-- Child Rows implementation -->
</asp:ListView>
Then you would need to bind the event to the ListView.ItemCommand.
protected void CustomersList_ItemCommand(object sender, ListViewCommandEventArgs e)
{
if (e.CommandName = "Select")
{
if (e.Item.ItemType != ListViewItemType.DataItem) return;
var dataItem = e.Item as ListViewDataItem;
if (dataItem == null) return;
var customer = dataItem.DataItem as Customer;
if (customer == null) return;
this.OrdersList.DataSource = GetChildRecords(customer.ID);
this.OrdersList.DataBind();
}
}