Boundfield in a new row - c#

I have a gridview with BoundField columns and I would like to insert a new row specifically for this BoundField.
Is this something that is possible to do?
The code is as follows:
<asp:GridView ID="grdAgreements" runat="server" AutoGenerateColumns="false" Width="100%"
AllowSorting="false" AlternatingRowStyle-BackColor="White"
HeaderStyle-BackColor="White" HeaderStyle-ForeColor="GrayText"
Font-Names="Arial" Font-Size="11" DataKeyNames="AgreementId" OnRowCreated="grdAgreements_RowCreated" >
<rowstyle height="24" />
<Columns>
<asp:BoundField HeaderText="Agreement Number" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" DataField="AgreementNumber" SortExpression="AgreementNumber" ItemStyle-Width="110" ItemStyle-Font-Names="Arial" />
<asp:BoundField HeaderText="Description" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" DataField="Description" SortExpression="Description" ItemStyle-Width="100" ItemStyle-Font-Names="Arial" />
<asp:BoundField HeaderText="Start Date" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" DataField="StartDate" SortExpression="StartDate" ItemStyle-Width="125" ItemStyle-Font-Names="Arial" />
<asp:BoundField HeaderText="End Date" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" DataField="EndDate" SortExpression="EndDate" ItemStyle-Width="200" ItemStyle-Font-Names="Arial" />
<asp:BoundField HeaderText="Site Number" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" DataField="SiteNumber" SortExpression="SiteNumber" ItemStyle-Width="200" ItemStyle-Font-Names="Arial" />
</Columns>
<EmptyDataTemplate>
There are no agreements to display.
</EmptyDataTemplate>
</asp:GridView>
What I would like to happen is that instead of the BoundField I would like to have the SiteNumber databound to a new row that I could stick in a div or panel.
How would I go about doing this?

Let me know if I am not understanding it right but if you want to customize the layout of the field you can use TemplateField instead of BoundField
<asp:TemplateField HeaderText="SiteNumber" SortExpression="SiteNumber">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("SiteNumber") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
But if you are thinking of moving that particular column in to a new row then you will have to look into other databound controls like ListView or Repeater as GV markup isn't that customizable.

As per the usual time constraints I didn't go through and figure out the best way to use the Listview for my needs but I did figure a way to get the layout that I was looking for using styled tables within a TemplateField and ItemTemplate. The following code is what I came up with and hopefully this will help someone else looking for a similar solution.
If time constraints are not on your plate I highly suggest looking further into the Listview control.
P.S. The css I used was a huge PITA to get everything styled perfect but it was definitely worth it IMHO.
And this was all within a GridView BTW
<asp:TemplateField>
<ItemTemplate>
<div class="EquipmentTable1" >
<table >
<tr>
<td>
Customer Equipment
</td>
<td>
Contract
</td>
<td >
Contract Number
</td>
<td>
Modality
</td>
</tr>
<tr>
<td>
<%--TODO link this to the customer equipment record pulled from the services web portal guide part 1 document--%>
<%# Eval("CustomerEquipmentID") %>
</td>
<td >
<%--Link to the agreement page and
pass in the agreement id as a query string to do a lookup of the agreement--%>
<%# Eval("AgreementID") %>
</td>
<td>
<%# Eval("AgreementLineID") %>
</td>
<td>
<%# Eval("ModalityID") %>
</td>
</tr>
</table>
</div>
<div class="EquipmentTable2" >
<table >
<tr>
<td>
Product
</td>
<td >
Model Number
</td>
<td>
Room Number
</td>
<td>
Date Installed
</td>
</tr>
<tr>
<td >
<%# Eval("Product") %>
</td>
<td>
<%# Eval("ModelNumber") %>
</td>
<td>
<%# Eval("RoomNumber") %>
</td>
<td>
<%# Eval("DateInstalled") %>
</td>
</tr>
</table>
</div>
</ItemTemplate>
</asp:TemplateField>

Related

Telerik RadGrid Custom Header (Not a Group Header)

I am developing a telerik radgrid on aspx. I simply want to add a row above the column headers, to show how columns are logically related. For example, 4 columns display data for 2014, and 4 columns for 2015.
I have the column headers, and the data, of course. I just need this additional info. Thanks.
Once you begin customizing the header, you lose the ability to automatically build the table. You will have to customize main header, the subheaders, and the columns.
The following page on Telerik's website has an example of how to create a header template with a double row header. Below is the code example from that page.
<telerik:RadGrid ID="RadGrid1" runat="server" AllowSorting="True" AutoGenerateColumns="false">
<MasterTableView>
<Columns>
<telerik:GridBoundColumn HeaderText="ContactName" DataField="ContactName" UniqueName="ContactName">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn UniqueName="TemplateColumn">
<HeaderTemplate>
<table id="Table1" cellspacing="1" cellpadding="1" width="300" border="1">
<tr>
<td colspan="2" align="center">
<b>Address</b>
</td>
</tr>
<tr>
<td width="50%">
<b>City</b>
</td>
<td width="50%">
<b>Postal code</b>
</td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<table id="Table2" cellspacing="1" cellpadding="1" width="300" border="1">
<tr>
<td width="50%">
<%# DataBinder.Eval(Container.DataItem"City") %>
</td>
<td width="50%">
<%# DataBinder.Eval(Container.DataItem"PostalCode") %>
</td>
</tr>
</table>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>

Migrating a web form to web-form with Master

I have a web form up.
Later on, I realized I need a Master Page with a navigation that other web forms should follow.
I am in the process of manually migrating.
Taking this approach, Create Master Page -> Cut from web form -> Paste to web form with master -> erase the old web form.
As following. (I didn't create a navigation control yet, to not complicate the process further).
[New Master Page]
</asp:ContentPlaceHolder>
</div>
</form>
[Old Web Form]
<asp:EntityDataSource ID="entityDataSource" runat="server" ConnectionString="name=VideoLibraryEntities" DefaultContainerName="VideoLibraryEntities" EnableDelete="True" EnableFlattening="False" EnableInsert="True" EnableUpdate="True" EntitySetName="Clips" EntityTypeFilter="Clipo" OnSelecting="EntityDataSource_Selecting">
</asp:EntityDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" DataSourceID="entityDataSource">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowSelectButton="True" />
</Columns>
</asp:GridView>
<div>
<h1>Sending Email</h1>
<table>
<tr>
<td>From:</td>
<td>
<asp:TextBox ID="txtFrom" runat="server" Width="250px"></asp:TextBox>
</td>
</tr>
<tr>
<td>From EMail:</td>
<td>
<asp:TextBox ID="txtFromEmail" runat="server" Width="250px"></asp:TextBox>
</td>
</tr>
<tr>
<td>To:</td>
<td>
<asp:TextBox ID="txtTo" runat="server" Width="250px"></asp:TextBox>
</td>
</tr>
<tr>
<td>To Email:</td>
<td>
<asp:TextBox ID="txtToEmail" runat="server" Width="250px"></asp:TextBox>
</td>
</tr>
<tr>
<td>Subject:</td>
<td>
<asp:TextBox ID="txtSubject" runat="server" Width="250px"></asp:TextBox>
</td>
</tr>
<tr>
<td>Message:</td>
<td>
<asp:TextBox ID="txtMessage" runat="server" TextMode="MultiLine" Height="138px"
Width="467px"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2" align="right">
<asp:Button ID="btnSend" runat="server" Text="Send Email"
onclick="btnSend_Click" />
</td>
</tr>
</table>
<asp:Label ID="Label1" runat="server" ForeColor="Blue" />
</div>
</form>
Now shall I create a Master page with navigation and just paste the old web form into the new one?
Thanks.

Repeater data inside template column of radgrid does not show when we do export to CSV

I have a RadGrid to display subscribers list and a repeater control with two fields. Repeater is placed inside template column of grid when I click on export to csv button of grid then other column of grid are export but template column with repeater not.Could anyone please help me?
<telerik:GridTemplateColumn HeaderText="Email Address/Verified Status" DataField="SubscriberEmailAddress"
Groupable="false" AllowFiltering="false" UniqueName="SubscriberEmailAddress">
<ItemTemplate>
<asp:Repeater ID="EmailAddressRepeater" runat="server">
<ItemTemplate>
<table style="width: 100%">
<tr>
<td style="width: 80%;">
<asp:Label ID="EmailAddressLabel" runat="server" Text='<%#Eval("News_Subscriber_Email_Map_Email_Address") %>' />
</td>
<td>
<asp:CheckBox ID="EmailAddressVerifiedCheckBox1" runat="server" Checked='<%# Convert.ToBoolean(Eval("News_Subscriber_Log_Verified_Status").ToString())%>' />
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Wrap="false" Width="20%" />
<HeaderStyle VerticalAlign="Top" HorizontalAlign="Left" Wrap="false" Width="20%" />
</telerik:GridTemplateColumn>
CSV is text-Based format it doesn't support complex structures like tables.

Displaying search results in a Website

I am working on a website where i need to search for items from database and display it in page.I am using Datalist for displaying all the items .Now i need to display all the items according to some category.For example if i search for a two-wheeler it may have many categories or manufacturer's.Now I want to display it separately according to the categories.I can use many datalist to do that,but it will slow down the site.Instead which control can i use to do this.I searched the web but got no idea.So please give me sugessions to go about it.Any sugessions will be appreciated.
Code:
<asp:DataList ID="Dlitems" runat="server" RepeatDirection="Horizontal" RepeatColumns="4"
CellPadding="0" CellSpacing="15">
<ItemTemplate>
<table>
<tr>
<td>
<asp:ImageButton ID="ImgbtnProductImage" CssClass="imgdisp" ImageUrl='<%# Eval("ImagePath") %>'
CommandArgument='<%#Eval("ProductCode") %>' runat="server" CommandName="cmdView" />
</td>
</tr>
<tr>
<td>
<table>
<tr>
<td width="20px"></td>
<td>
<img src="../Database/images/inr.jpg" alt="addtocart" />
<asp:Label ID="lblproductprice" runat="server" Text='<%# Eval("Price") %>' CssClass="lbl" />
</td>
<td>
<asp:ImageButton ID="imgbtnaddtocart" runat="server" Height="25px" Width="25px" ImageUrl="~/Database/images/addtocart.JPG"
ToolTip="Add to Cart" CommandArgument='<%#Eval("ProductCode")+","+ Eval("ProductName")+","+ Eval("ImagePath")+","+ Eval("Price")+","+ Eval("LongDescription") %>'
CommandName="addtocart" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
You can take benefit of gridview.
Bind you gridview data.
And letter merge the rows.
For an example you can use the below link
http://www.codeproject.com/Articles/34337/How-to-merge-cells-with-equal-values-in-a-GridView
Edit 1
Some links
How to display group data separately using DataList in ASP.NET?
http://aspnettuts.wordpress.com/2010/10/21/asp-net-repeater-group-recordsdata-delete-selected-rows/
You should go for a Repeater control.
Example on Repeater
<asp:Repeater runat="server" ID="Repeater1">
<ItemTemplate>
<asp:ImageButton ID="ImgbtnProductImage" CssClass="imgdisp" ImageUrl='<%# Eval("ImagePathForTwoWheeler")%> + <%# Eval("ImagePathForCategory") %>'
CommandArgument='<%#Eval("ProductCode") %>' runat="server" CommandName="cmdView" />
</ItemTemplate>
</asp:Repeater>

How to add paging capabilities to the Repeater control in ASP.Net?

I have an asp.net Repeater control .I have to display only 5 rows in the repeater. I searched about it in Google but most of the resources are talking about how to do it with DataSet. In my case, I am using SqlDataSource. So I can have paging in this Repeater control?
ASP.NET Code:
<asp:Repeater ID="Repeater3" runat="server" DataSourceID="SqlDataSource3">
<HeaderTemplate>
<div>
<table border="1">
<thead>
<tr>
<td colspan="3">
<center> <strong>Safety Quizzes Record</strong> </center>
</td>
</tr>
<tr>
<td>
<center> <strong>Quiz Title</strong> </center>
</td>
<td>
<center> <strong>Date & Time</strong> </center>
</td>
<td>
<center> <strong>Score</strong> </center>
</td>
</tr>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<p>
<%# Eval("Title") %>
</p>
</td>
<td>
<p>
<%# Eval("DateTimeComplete") %>
</p>
</td>
<td>
<p>
<%# Eval("Score") %>
</p>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</div>
</FooterTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:testConnectionString %>" SelectCommand="SELECT dbo.Quiz.Title, dbo.UserQuiz.DateTimeComplete, dbo.UserQuiz.Score
FROM dbo.employee INNER JOIN
dbo.UserQuiz ON dbo.employee.Username = dbo.UserQuiz.Username INNER JOIN
dbo.Quiz ON dbo.UserQuiz.QuizID = dbo.Quiz.QuizID
WHERE (dbo.employee.Username = #Username)">
<SelectParameters>
<asp:Parameter Name="Username" />
</SelectParameters>
</asp:SqlDataSource>
UPDATE:
What I want is showing only 5 items in the Repeater and the others will be listed on the other pages of the Repeater. So how I can have Pagining with SqlDataSource as mentioned above.
The Repeater control does not support paging out-of-the-box.
You could however implement it but it would require you to manually code it.
I would like to recommend you to change the Repeater control for the ListView control
Differences:
Repeater. This control does not support paging, updating, inserting or deleting operations out-of-the-box, if you want these features you would need to manually code them.
ListView. This is the most flexible of all data-bound controls. It's based on templates like the Repeater and DataList controls. It does support CRUD operations automatically mapping the operations agains your data source control. It does support server paging, and you can customize pretty much everything
BTW, since you are using a SqlDataSource, you would have to manually add paging code to your queries or store procedures, you could change that behavior if you use a LinqDataSource or an EntityDataSource
This is a simplified ListView markup:
<asp:ListView runat="server" ID="lv"
DataSourceID="lds" DataKeyNames="emp_id"
EnableModelValidation="false"
EnablePersistedSelection="false"
>
<LayoutTemplate>
<br />
<br />
A static header
<div runat="server" id="itemPlaceHolder"></div>
<br />
<asp:DataPager runat="server" PageSize="4">
<Fields>
<asp:NextPreviousPagerField
ButtonType="Button"
ShowFirstPageButton="true"
ShowLastPageButton="true"
/>
</Fields>
</asp:DataPager>
</LayoutTemplate>
<ItemTemplate>
<div style="background-color:Gray">
First Name
<div><asp:Label runat="server" ID="lbl" Text='<%# Eval("fname") %>'></asp:Label></div>
<br />
<asp:GridView ID="GridView1" runat="server" DataSource='<%# Eval("Achivements") %>' />
<br />
<asp:LinkButton ID="LinkButton1" Text="Select" CommandName="Select" runat="server" />
<asp:LinkButton ID="LinkButton2" Text="Edit" CommandName="Edit" runat="server" />
<asp:LinkButton ID="LinkButton4" Text="Delete" CommandName="Delete" runat="server" />
</div>
</ItemTemplate>
<ItemSeparatorTemplate>
<hr />
</ItemSeparatorTemplate>
</asp:ListView>
Please use the PagedDataSource shown at link http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.pageddatasource.aspx

Categories