Asp.Net adding an extra td - c#

I'm trying to use an ASP:DataList to display data from my data source. Everything works ok, except I'm getting ASP to add an extra column when there isn't one. The Header Template and Item Template are shown below
<asp:DataList runat="server" ID="xTable" DataKeyField="PK_PurchaseID" DataSourceID="SqlDataSource1" RepeatLayout="table" CssClass="table">
<HeaderTemplate>
<td>PuchaseID</td>
<td>Last Name</td>
<td>First name</td>
<td>Address1</td>
<td>Email Sent</td>
</HeaderTemplate>
<ItemTemplate>
<td><%# Eval("PK_PurchaseID") %></td>
<td><%# Eval("LastName") %></td>
<td><%# Eval("FirstName") %></td>
<td><%# Eval("Address1") %></td>
<td><%# Eval("[Email Sent]") %></td>
</ItemTemplate>
</asp:DataList>
And is the the DOM object created. I would expect 5 columns in the table yet it is rendered as 6
<table class="table" id="xTable" style="border-collapse: collapse;" cellspacing="0">
<tbody><tr>
<td>
<td>PuchaseID</td>
<td>Last Name</td>
<td>First name</td>
<td>Address1</td>
<td>Email Sent</td>
</tr><tr>
<td>
<td>3</td>
<td>Albdddim</td>
<td>James </td>
<td>1----63rd Ave.</td>
<td>true</td>
</tr>
I can not figure you why an initial column is being created. I changed the CSS, even removed it and still the same result. I have verified the SQL only returns the 5 columns (even if it returned more or less that shouldn't make a difference)
Thanks Chris

The HeaderTemplate and ItemTemplate are meant to be td elements so it automatically creates the td. If you do something like this
<asp:DataList runat="server" ID="xTable" DataKeyField="PK_PurchaseID" DataSourceID="SqlDataSource1" RepeatLayout="table" CssClass="table">
<HeaderTemplate>
PuchaseID
<td>Last Name</td>
<td>First name</td>
<td>Address1</td>
<td>Email Sent</td>
</HeaderTemplate>
<ItemTemplate>
<%# Eval("PK_PurchaseID") %>
<td><%# Eval("LastName") %></td>
<td><%# Eval("FirstName") %></td>
<td><%# Eval("Address1") %></td>
<td><%# Eval("[Email Sent]") %></td>
</ItemTemplate>
</asp:DataList>
It would put the purchase ID in the first td that is created and then fill out the table like you want.

Related

Dynamically change repeater's data item

I have an <asp:Repeater> control that loads its data from a database.
To specify which column will be used where in the .aspx file, I use inside the Repeater's ItemTempate
<%# DataBinder.Eval(Container.DataItem, "column1")%>
Now when I need to make changes eg. I want another column instead of column1, I have to open Visual Studio, make the changes, publish the project again, and upload it to the server.
How can this control be more adjustable without having to change the source code each time?
Is there any other control that will do what I need better?
ASPX markup:
<table class="uk-table">
<thead>
<tr>
<th>User Name</th>
<th>Date 1</th>
<th>Date 2</th>
<th>State</th>
</tr>
</thead>
<tbody>
<asp:Repeater runat="server" ID="Repeater2">
<HeaderTemplate></HeaderTemplate>
<ItemTemplate>
<tr class="uk-table-middle">
<td><%# DataBinder.Eval(Container.DataItem,"column1")%></span></td>
<td><%# DataBinder.Eval(Container.DataItem,"column2")%></td>
<td><%# DataBinder.Eval(Container.DataItem,"column3")%> </td>
<td><%# DataBinder.Eval(Container.DataItem,"column4")%></span></td>
</tr>
</ItemTemplate>
<FooterTemplate></FooterTemplate>
</asp:Repeater>
</tbody>
</table>
You need to define a condition like the following and save your condition either in the database or an XML file or even in the web.config (on yours) and do the following. Don't forget to retrieve your condition out of the repeater if you wanna apply to all rows:
<%
var myCondition = true; // whatever it could be...
%>
<asp:Repeater runat="server" ID="Repeater2">
<HeaderTemplate></HeaderTemplate>
<ItemTemplate>
<tr class="uk-table-middle">
<% if (mycondition){ %>
<td><%# DataBinder.Eval(Container.DataItem,"column1")%></span></td>
<td><%# DataBinder.Eval(Container.DataItem,"column2")%></td>
<% }else{ %>
<td><%# DataBinder.Eval(Container.DataItem,"column2")%></td>
<td><%# DataBinder.Eval(Container.DataItem,"column1")%></span></td>
<% } %>
<td><%# DataBinder.Eval(Container.DataItem,"column3")%> </td>
<td><%# DataBinder.Eval(Container.DataItem,"column4")%></span></td>
</tr>
</ItemTemplate>
<FooterTemplate></FooterTemplate>
</asp:Repeater

Implement accordion within table and asp:repeater

I create table inside a repeater
and the data appears correctly, it will be two records looks like in the image below.
what i want: how to make accordion when user clicks on the deposit number(Example 16), new table will appear and contain data.
this is the repeater the first repeater code:
<asp:Repeater ID="rptDep" runat="server" >
<HeaderTemplate>
<table class="table table-hover table-striped table-condensed table-bordered table-responsive">
<tr>
<th>Deposit No.</th>
<th>Custom Declaration No.</th>
<th>Category</th>
<th>Location</th>
<th>Goods Description</th>
<th>Units Balance</th>
<th>WT Balance</th>
<th>Goods Balance Amount(LC)</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td> <%#Eval("depNo") %></td>
<td><%#Eval("customDec") %></td>
<td><%#Eval("category") %></td>
<td><%#Eval("location") %></td>
<td><%#Eval("goodDesc") %></td>
<td><%#Eval("unitsBal") %></td>
<td><%#Eval("wtBal") %></td>
<td><%#Eval("lcBal") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
I know that it will be a second repeater, but how to implement that, or how to use foreach statement?
I got it, I found the solution by reading this article:
Implement Nested Repeater (Repeater inside Repeater) with example in ASP.Net using C# and VB.Net

ASP.NET UpdatePanel Set value for Checkbox

I am using a ListView that contains a checkbox. I would like the checkbox to automatically update a bit field in my database from False to True (or visa versa) when the box is checked.
I am not familiar with the update panel and I'm struggling to find a way to achieve this.
My List View
<asp:ListView ID="ListView1" runat="server" DataKeyNames="NotificationID" DataSourceID="SqlDataSource1">
<EmptyDataTemplate>
<table runat="server" style="">
<tr>
<td>No notifications exist.<br /> NOTE: You must be logged in to see notificaitons</td>
</tr>
</table>
</EmptyDataTemplate>
<ItemTemplate>
<tr class="odd gradeX">
<td><span style="display: none;"><%# ("00000000" + Eval("DateDescNumber")).TxtStrRight(8) %> - </span><%# GlobalUtilities.GetDiffDate(Convert.ToDateTime(Eval("DateTimeLogged"))) %></td>
<td><%# Eval("UserName") %></td>
<td><%# Eval("NotificationTitle") %></td>
<td class="center"><%# Eval("NotificationMessage") %></td>
<td class="center">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:updatepanel id="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:CheckBox ID="CheckBoxMarkedAsRead" runat="server"
Checked='<%# Eval("MarkedAsRead") %>'
AutoPostBack="true"
Visible="true"
Text =" Not Selelected"
oncheckedchanged="CheckBox_MarkedAsRead_CheckedChanged" />
</ContentTemplate>
</asp:updatepanel>
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table cellpadding="0" cellspacing="0" border="0" class="responsive dynamicTable display table table-bordered" width="100%">
<thead>
<tr>
<th style="width:80px">Date</th>
<th>From</th>
<th>Notice</th>
<th>Description</th>
<th class="ch" style="width:53px;">Read</th>
</tr>
</thead>
<tbody>
<asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
</tbody>
</table>
</LayoutTemplate>
</asp:ListView>
I have gone as far as creating the CheckBox_MarkedAsRead_CheckedChanged event in my Code behind (at least I think this is what I should do) but my attempts to script a solution in the code behind has been fail after fail.

Is there a way to add DataTables Column Filter Add-on to my project

I am currently trying to add an add-on of DataTables Column Filter Add-on. Is there a way to add this add-on using Microsoft Visual Studio Express 2012 for web? Do i have to add the js scripts or something. And i can't get the CSS to show over the current data table, is there something that i am missing.
The initialization code is this:
Is there somewhere i am missing something.
$(document).ready(function(){
$('#example').dataTable()
.columnFilter();
});
<%# Page Title="Home Page" Language="c#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Home.aspx.cs" Inherits="Glossary._Default" %>
<asp:Content runat="server" ID="HeaderContent" ContentPlaceHolderID="HeadContent">
<link href="media/css/jquery.dataTables.css" rel="stylesheet" />
</asp:Content>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<HeaderTemplate>
<table id="datatable">
<thead>
<tr>
<th>Term</th>
<th>Definition Number</th>
<th>Definitnion Version Number </th>
<th>Definition</th>
<th>Amplifying Explanation Text</th>
<th>See Also</th>
<th>Authoritative Source</th>
<th>Scope</th>
<th>Domain</th>
<th>Governance State</th>
<th>Last Updated Time</th>
</tr>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container.DataItem, "TermText").ToString() %></td>
<td><%# DataBinder.Eval(Container.DataItem, "DefNbr").ToString() %></td>
<td><%# DataBinder.Eval(Container.DataItem, "DefVerNbr").ToString() %></td>
<td><%# DataBinder.Eval(Container.DataItem, "DefText").ToString() %></td>
<td><%# DataBinder.Eval(Container.DataItem, "AmplifyingExplanationText").ToString() %></td>
<td><%# DataBinder.Eval(Container.DataItem, "SeeAlsoText").ToString() %></td>
<td><%# DataBinder.Eval(Container.DataItem, "AuthoritativeSrcText").ToString() %></td>
<td><%# DataBinder.Eval(Container.DataItem, "ScopeName").ToString() %></td>
<td><%# DataBinder.Eval(Container.DataItem, "DomnName").ToString() %></td>
<td><%# DataBinder.Eval(Container.DataItem, "GovernanceStateName").ToString() %></td>
<td><%# DataBinder.Eval(Container.DataItem, "LastUpdtTimestamp").ToString() %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Glossary %>"
SelectCommand="SELECT [TermText], [DefNbr], [DefVerNbr], [DefText], [AmplifyingExplanationText], [SeeAlsoText], [AuthoritativeSrcText], [ScopeName], [DomnName], [GovernanceStateName], [LastUpdtTimestamp] FROM [Glossary] ORDER BY [TermText]"></asp:SqlDataSource>
<script src="media/js/jquery.js"></script>
<script src="media/js/jquery.dataTables.min.js"></script>
<script type="text/javascript">
$('#dataTable').dataTable();
</script>
</asp:Content>
Add
<div class="info"></div>
before table

c# asp.net repeater - create button based on condition

Basically what i would like to do is have a button which is only created for entries that have been flagged in a separate table for sending. So for example if i edit a record, i flag this other table and would like a send button to appear next to that record via the repeater below - is this possible? Can i do a check by calling a method for example unsure :(
<asp:Repeater ID="DepartmentsList" runat="server">
<HeaderTemplate>
<table id="grouptable" class="table table-bordered table-striped">
<thead>
<tr>
<th>Send</th>
<th>ID</th>
<th>Name</th>
<th>Last Modified</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<input type="checkbox" name="sendSelect[]" value="<%# Eval("Dept_ID") %>"</input></td>
<td><%# Eval("Dept_ID") %></td>
<td><%# Eval("DESC") %> </td>
<td><%# Eval("CHG_DATE") %></td>
<td><a class="btn btn-info" href="<%# Eval("gURL") %>"><i class="icon-pencil icon-white"></i> Edit</a><asp:Button ID="Button1" runat="server" Text="Send" /></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</tbody>
</table>
</FooterTemplate>
</asp:Repeater>
You can do a check and inspect the current data record being bound to the repeater by using the DepartmentsList_OnItemDataBound event. It gives you all the power you need to dynamically change what's being bound and created in the repeater's item.

Categories

Resources