I have a table containing data and in the first field it has translatable labels.
I would like to be able to set a width in the label column but make it so that if someone translates the labels and the text is longer, that is expands the column but up to a given point.
Example label column requirements:
Width: 200px;
Expandable: true;
Max Expanding: 300px;
Note: I am specifically asking how to enable this functionality but it must have a maximum width when expanding.
<table id="tblCustTypes" class="tblTop">
<tr>
<td class="auto-style1">
<asp:Label ID="lblCustType" runat="server" Text="Cust Type"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtCustomerType" runat="server" Width="20%" class="autosuggest" CssClass="autosuggest" OnChange="onSave();" OnTextChanged="txtCustomerType_TextChanged" AutoPostBack="True"></asp:TextBox>
<asp:Label ID="lblTempCustType" runat="server" Visible="false"></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="lblDescription" runat="server" Text="Description"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtDescription" runat="server" Width="35%"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="lblApplyVAT" runat="server" Text="Apply VAT"></asp:Label>
</td>
<td>
<asp:RadioButtonList ID="rblApplyVAT" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Selected="True" Value="1">Yes</asp:ListItem>
<asp:ListItem Value="0">No</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="lblProduceInvoices" runat="server" Text="Produce Invoices"></asp:Label>
</td>
<td>
<asp:RadioButtonList ID="rblProduceInvoices" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Selected="True" Value="1">Yes</asp:ListItem>
<asp:ListItem Value="0">No</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="lblPurchaseSale" runat="server" Text="Purchase/Sale"></asp:Label>
</td>
<td>
<asp:RadioButtonList ID="rblPurchaseSale" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Value="P">Purchase</asp:ListItem>
<asp:ListItem Selected="True" Value="S">Sale</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="lblTerms" runat="server" Text="Terms (Days)"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtTerms" runat="server" Width="5%"></asp:TextBox></td>
</tr>
<tr>
<td>
<asp:Label ID="lblLastUpdated" runat="server" Text="Last Updated"></asp:Label>
</td>
<td>
<asp:Label ID="lblLastUpdatedVal" runat="server" Text=""></asp:Label>
</td>
</tr>
</table>
The comments provided the solution. What browser are you using? The min-width property isn't compatible with some older browsers, including IE 8.
I found that putting this in my .aspx file (or relevant content control) did the trick.
<style>
.tblTop > tbody > tr > td {
min-width:50px;
max-width: 100px;
border: 1px solid black;
}
</style>
<table class="tblTop">
<tr>
<td>Hello</td>
<td>Goodbye</td>
</tr>
<tr>
<td>Some very long string that will extend to the maximum width that I set and force the words to wrap around.</td>
<td>Goodbye</td>
</tr>
</table>
If you're using the server-side control (not sure why you would here):
<asp:Table CssClass="tblTop"> . . .
I used the selectors (>) so that the properties wouldn't apply to the radio-button list control and other ASP controls that might create a table within a table cell.
Edit: After re-reading your question, I see that you only wanted the first column to change. In that case, using the :first-child property is the way to go, but you will still want selectors so that your radio-button lists don't set their columns with that style. The code would be as follows:
<style>
.tblTop > tbody > tr:first-child {
min-width:50px;
max-width: 100px;
border: 1px solid black;
}
</style>
Usually to force a width within a table , you use table-layout:fixed; Explanation on http://www.w3.org/wiki/CSS/Properties/table-layout .
It should work too with max-width: DEMO
basic CSS for a max-width of 80px:
table {
table-layout:fixed;
}
table tr :first-child {
max-width:80px;
}
Related
I created a table to organize my items on a page. The page is an edit page for a property.
I used colspan to expand rows and put a textbox within rows and set the textbox wdith to 100%, However, the textbox width still only takes the space of 1 column not 3 columns like I expected here is the code
<table align="left" style="width: 100%; float: left" class="FormFormatTable">
<tr>
<td style="width: 10%; height: 60px">Alert Name</td>
<td colspan="3" style=" ">
<asp:TextBox CssClass="inputBoxes" ID="txtBox_alertName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 10%; height: 60px;">Alert</td>
<td style="height: 60px; ">
<asp:DropDownList ID="ddl_AlertTime" runat="server">
<asp:ListItem Value="1">After</asp:ListItem>
<asp:ListItem Value="0">Immediately</asp:ListItem>
</asp:DropDownList>
</td>
<td style="height: 60px; ">
<input id="demo_vertical0" type="number"/></td>
<td style="height: 60px">
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>Seconds</asp:ListItem>
<asp:ListItem>Minutes</asp:ListItem>
<asp:ListItem>Hours</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td style="width: 10%">Severity</td>
<td style=" height: 60px"" >
<asp:DropDownList ID="ddl_Severity" runat="server">
<asp:ListItem Value="1">After</asp:ListItem>
<asp:ListItem Value="0">Immediately</asp:ListItem>
</asp:DropDownList>
</td>
<td style=""> </td>
<td> </td>
</tr>
<tr style="height:60px">
<td style="width: 10%">Receipients</td>
<td colspan="3" style="">
<asp:TextBox CssClass="inputBoxes" ID="txtBox_Receipients" runat="server"></asp:TextBox>
</td>
</tr>
<tr style="height:60px">
<td style="width: 10%">Subject Title</td>
<td colspan="3" style="">
<asp:TextBox CssClass="inputBoxes" ID="txtBox_SubjectTitle" runat="server"></asp:TextBox>
</td>
</tr>
<tr style="height:60px">
<td style="width: 10%">Alert Messsage</td>
<td colspan="3" style="">
<asp:TextBox CssClass="inputBoxes" ID="txtBox_AlertMessage" runat="server"></asp:TextBox>
</td>
</tr>
<tr style="height:60px">
<td style="width: 10%; ">Notification Window</td>
<td style=" ">
<asp:TextBox CssClass="inputBoxes" ID="txtBox_NotificationWindow" runat="server"></asp:TextBox>
</td>
<td style=" "></td>
<td style="height: 60px"></td>
</tr>
<tr style="height:60px">
<td style="width: 10%; ">Notification Frequency</td>
<td style=" ">
<input id="demo_vertical" type="number"/>
</td>
<td style=" "></td>
<td style="height: 60px"></td>
</tr>
<tr style="height:60px">
<td style="width: 10%">Fields to Display in Details</td>
<td colspan="3" style="">
<asp:TextBox CssClass="inputBoxes" ID="txtBox_SubjectTitle3" runat="server"></asp:TextBox>
</td>
</tr>
</table>
css is simple just this
.inputBoxes {
width: 100%;
}
why is this?
a screenshot of my page on my computer
In you HTML
the Alert Name , Receipients ,Subject Title ,Alert Messsage ,Fields to Display in Details TextBoxs take 3 columns .
Notification Window take one columns because you don't set colspan
you must add colspan="3" to your td of notfication
<td colspan="3" style=" ">
<asp:TextBox CssClass="inputBoxes" ID="txtBox_NotificationWindow" runat="server"></asp:TextBox>
</td>
You have an extra quote in the following line (the cell definition that contains your ddl_Severity control).
<td style=" height: 60px"" >
Maybe remove this quote, and see if that fixes it.
I have many linkbutton placed on a webform everything working correctly til yesterday. But now now my ajax extenders are not working and linkbuttons are posting back.
some of my code is
<table width="460px">
<tr>
<td colspan="2"
style=" color: #C48239; font-style: normal; font-size: 18px; font-family: 'Bookman Old Style'; text-align:center;height:22px;">
Manage Your Profile</td>
</tr>
<tr>
<td>
<asp:LinkButton ID="lnk_per_pro" runat="server" CssClass="linkButton"
PostBackUrl="~/User/Edit_profile.aspx">Edit Personal Profile</asp:LinkButton> </td>
<td>
<asp:LinkButton ID="lnk_par_pro" runat="server" CssClass="linkButton">Edit Partner's Profile</asp:LinkButton></td>
</tr>
<tr>
<td>
<asp:LinkButton ID="lnk_con_det" runat="server" CssClass="linkButton"
PostBackUrl="~/User/Edit_profile.aspx">Edit Contect Details</asp:LinkButton></td>
<td>
<asp:LinkButton ID="lnk_add_photos" runat="server" CssClass="linkButton">Add Photos</asp:LinkButton></td>
</tr>
<tr>
<td>
<asp:LinkButton ID="lnk_hob" runat="server" CssClass="linkButton"
PostBackUrl="~/User/Edit_profile.aspx">Edit Hobbies and Interests</asp:LinkButton></td>
<td>
<asp:LinkButton ID="lnk_del_pro" runat="server" CssClass="linkButton">Remove/Delete Profile</asp:LinkButton></td>
</tr>
</table></center>
</div>
</div><!-- div 2 end-->
<div id="div3">
<div id="inbox1"><b>About Myself</b>
</div>
<div id="inbox2">Partner Prefrence
</div>
</div>
<div id="div4">
<div id="indiv4"><b>Basics Information</b>
<div id="edit4">
<asp:LinkButton ID="lnk_edit" runat="server" CssClass="link"
PostBackUrl="~/User/Edit_profile.aspx"> Edit</asp:LinkButton> <img src="images/edit.png" alt="" />
</div>
</div>
<div id="indiv24">
<div id="lt"><table class="style1" >
<tr>
<td style="color: #666666; width: 180px">
Age</td>
<td style="width: 180px">
<asp:Label ID="lbl_age2" runat="server" Text="Label"></asp:Label>
</td></tr><tr>
<td style="color: #666666; width: 180px">
Mobile Number</td>
<td>
<asp:Label ID="lbl_mob2" runat="server" Text="Label"></asp:Label>
</td>
</tr>
<tr>
<td style="color: #666666; width: 180px">
Height</td>
<td style="width: 180px">
<asp:Label ID="lbl_height2" runat="server" Text="Label"></asp:Label>
</td></tr><tr>
<td style="color: #666666; width: 180px">
Email Id</td>
<td>
<asp:Label ID="lbl_eml2" runat="server" Text="Label"></asp:Label>
</td>
</tr>
<tr>
<td style="color: #666666; width: 180px">
Marital Status</td>
<td style="width: 180px">
<asp:Label ID="lbl_mar_sts2" runat="server" Text="Label"></asp:Label>
</td></tr>
</table></div>
a link is shown on hover of linkbutton
javascript:webforms_DoPostbackWithOption:(NewPostBackoption("","false",true,"false"));
Do you have any validation controls inside application , check once by setting the Cause validation = false to link button control .
Some times your system has changed to old time(like one year back) also the link buttons won't redirect
There may be validation controls inside application , check once by setting the Cause validation = false to link button control .
below is my listview code example, while the products are populating, I want to check every single one of them against my database whether it's quantity is 0, how can add a method in code behind to do this:
I tried doing this under the onselectedindexchanged event but got the 'Object reference not set to an instance of an object.' exception :
Appreciate any help given. Thanks!
using (XXXShop db = new XXXShop ())
{
var availability = from p in db.Products
where p.Quantity == 0
select p;
(ListView_Products.FindControl("litStatus") as Literal).Text = "Unavailable";
}
ListView code:
<asp:ListView ID="ListView_Products" runat="server" DataKeyNames="ProductID"
DataSourceID="EDS_ProductsByCategory" GroupItemCount="3"
onselectedindexchanged="Page_Load">
<EmptyDataTemplate><table runat="server"><tr><td>No data was returned.</td></tr></table></EmptyDataTemplate>
<EmptyItemTemplate><td runat="server" /></EmptyItemTemplate>
<GroupTemplate><tr ID="itemPlaceholderContainer" runat="server"><td ID="itemPlaceholder" runat="server"></td></tr></GroupTemplate>
<ItemTemplate>
<td runat="server">
<table border="0" width="295">
<%-- Product pics --%>
<tr>
<td style="vertical-align: middle; text-align: center;">
<a href='ProductDetails.aspx?productID=<%# Eval("ProductID") %>'>
<image src='Catalog/Images/Thumbs/<%# Eval("ProductImage") %>' width="195" height="270" border="0">
</a>
</td>
</tr>
<tr>
<%-- Product info, description, price...etc --%>
<td style="width: 250px; vertical-align: middle; text-align: center; padding-bottom: 5px;">
<b>Price: </b><%# Eval("UnitCost", "{0:c}")%>
</td>
</tr>
<tr>
<td style="width: 250px; vertical-align: middle; text-align: center; padding-bottom: 25px;">
<asp:Literal ID="litStatus" runat="server" />
</td>
</tr>
</table>
</td>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table ID="groupPlaceholderContainer" runat="server">
<tr ID="groupPlaceholder" runat="server"></tr>
</table>
</td>
</tr>
<tr runat="server"><td runat="server"></td></tr>
</table>
</LayoutTemplate>
</asp:ListView>
I haven't done that much with ASP.NET or used the ListView so i don't know if there might be better ways to do this, but you could add a method to your codebehind that can format your data the way you want. Like the following:
protected string FormattedQuantity(int quantity)
{
return quantity > 0 ? quantity.ToString() : "Unavailable";
}
You should then be able to use this formatter anywhere in your aspx file by doing the following:
<asp:Label ID="OccurrenceLabel" runat="server"
Text='<%# FormattedQuantity((int)Eval("Quantity")) %>' />
Check it in the ListView.ItemDataBound event
I have a page with the following mark up
<%# Page Title="" Language="C#" MasterPageFile="~/CaseAdmin.master" AutoEventWireup="true" CodeBehind="AddExhibit.aspx.cs" Inherits="Prototype5.AddExhibit" %>
<h2 class="style2">
<strong><span style="color: #FFFFFF">Add Exhibit
Form</span></strong></h2>
<div style="width: 600px">
<table style="width: 303px" align="left">
<tr>
<td class="style26" style="background-color: #666666">
<p class="style5" style="color: #000000; background-color: #666666;">
<strong style="background-color: #666666">Select Existing Case ID:
</strong>
</p></td>
<td class="" style="background-color: #C0C0C0" align="left">
<asp:DropDownList ID="DropDownListcaseid" runat="server"
onselectedindexchanged="DropDownListcaseid_SelectedIndexChanged">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="DropDownListcaseid"
ErrorMessage="Please select a valid case id from the dropdown menu"
ForeColor="Red">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style4" colspan="2">
</td>
</tr>
</table>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:CMSSQL3ConnectionString1 %>"
SelectCommand="SELECT [CaseID] FROM [Cases]"></asp:SqlDataSource>
</div>
<div style="width: 603px; height: 75px; ">
<table style="height: 66px; width: 598px; top: 277px; left: 268px;"
align="left">
<tr>
<td class="bold"
style="color: #000000; background-color: #666666; width: 127px;">
<strong>Exhibit Type</strong></td>
<td class="bold" style="background-color: #666666; width: 228px;">
<span style="color: #000000">Exhibit Image</td>
<td class="bold" style="background-color: #666666; width: 111px;">
<span style="color: #000000">Stored Location</span></td>
<td class="bold" style="background-color: #666666; color: #000000;">
Officer ID</span></td>
</tr>
<tr>
<td class="style32" style="background-color: #C0C0C0; width: 127px;">
<asp:DropDownList ID="exhibitTypeDropDownList" runat="server">
<asp:ListItem></asp:ListItem>
<asp:ListItem>Hard Disk</asp:ListItem>
<asp:ListItem>Pen Drive</asp:ListItem>
<asp:ListItem>Laptop</asp:ListItem>
<asp:ListItem>Palm Devce</asp:ListItem>
<asp:ListItem>Mobile Phone</asp:ListItem>
<asp:ListItem>Tablet PC</asp:ListItem>
<asp:ListItem>Pager</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="exhibitTypeDropDownList"
ErrorMessage="Please Enter the type of exhibit. eg. Harddisk"
ForeColor="Red" ondisposed="addExhibitButton_Click">*</asp:RequiredFieldValidator>
</td>
<td class="style28" style="background-color: #C0C0C0; width: 228px;">
<asp:FileUpload ID="exhibitImageFileUpload" runat="server" />
</td>
<td class="style20" style="background-color: #C0C0C0; width: 111px;">
<asp:DropDownList ID="storedLocationDropDownList" runat="server">
<asp:ListItem></asp:ListItem>
<asp:ListItem>B-15/4</asp:ListItem>
<asp:ListItem>B-10/1</asp:ListItem>
<asp:ListItem>B-5/4</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="storedLocationDropDownList"
ErrorMessage="Please enter a valid stored location" ForeColor="Red"
ondisposed="addExhibitButton_Click">*</asp:RequiredFieldValidator>
</td>
<td class="style30" style="background-color: #C0C0C0">
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="officersSqlDataSource" DataTextField="PoliceID"
DataValueField="PoliceID" Width="79px" Height="26px">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="DropDownList1"
ErrorMessage="Please select a valid Officer id from the dropdown list"
ForeColor="Red" ondisposed="addExhibitButton_Click">*</asp:RequiredFieldValidator>
</td>
</tr>
</table>
</div>
<div style="width: 609px; height: 23px;">
</div>
<div style="margin-top:12px; width: 232px; text-align:left; font-size:1.3em;">
<asp:SqlDataSource ID="officersSqlDataSource"
runat="server"
ConnectionString="<%$ ConnectionStrings:CMSSQL3ConnectionString1 %>"
SelectCommand="SELECT PoliceID FROM PoliceOfficers"></asp:SqlDataSource>
<table align="left">
<tr>
<td align="center">
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ForeColor="Red"
HeaderText="The following errors occured." />
</td>
</tr>
</table>
</div>
<div style="margin-top:12px; width: 456px;">
<table style="width: 450px" align="left">
<tr>
<td align="center" colspan="3">
<asp:Label ID="messageLabel" runat="server" BackColor="White" ForeColor="Red"
Visible="False"></asp:Label>
</td>
</tr>
<tr>
<td align="center" style="width: 96px">
<asp:Button ID="cancelButton" runat="server" Text="Cancel"
onclick="cancelButton_Click" height="26px" width="101px" />
</td>
<td style="width: 237px">
</td>
<td align="center">
<asp:Button ID="addExhibitButton" runat="server" Text="Add Exhibit"
onclick="addExhibitButton_Click" />
</td>
</tr>
</table>
</div>
and the following interface look
I wish to perform validation on the page only when the "add exhibit button" is clicked. so in my code behind, i used an "if(page.isvalid)" to check for page validation when the button is clicked. However any other button i click fires the validation as well... I presume its because every button click tries to load a page and that calls the validator to action. how do i allow work around the validation such that, only the " add exhibit button" triggers the page validation?
You need to set the ValidationGroup property on the button and the validator. That way you can control what validation takes place.
The ValidationGroup property is an arbitrary tag that you can add to your validators and buttons to group them into logical units. So in your case, I would do this:
For your validators that are relevant for the add exhibit action.
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" ValidationGroup="AddExhibit" ...
For your button that triggers your add exhibit.
<asp:Button ID="addExhibitButton" ValidationGroup="AddExhibit"
Exporting from c#.net
I am getting a problem I have a form that when I export to excel as a result in excel Any ideas why is this happening I am including the ASP code below.
<%# Page Language="C#" MasterPageFile="~/masterpages/Admin.master" AutoEventWireup="true" CodeFile="members-search-adv.aspx.cs" Inherits="masteradmin_members_search_adv" Title="LISA - Life Insurance Settlement" %>
<%# Register TagPrefix="UC" TagName="Paging" Src="~/controls/Paging.ascx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script type="text/javascript" src="sorttable.js"></script>
Go to Quick Search
<h1>Contact Database - Advanced Search</h1>
<asp:Label ID="lblSearchCriteria" runat="server" Text="" ForeColor="blue"></asp:Label>
<table width="100%" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" width="50%">
<table border="0" cellpadding="3" cellspacing="1" style="height: 214px; width: 101%;">
<tr>
<td class="form1" align="right"><strong>OpenSearch:</strong></td>
<td class="form2">
<asp:TextBox ID="txtSearch" runat="server" CssClass="fields" Width="245px" ></asp:TextBox><b>*</b> <br><b>*</b><small>Search By Company Name, First Name, Last Name, Tags, Comments</small></td>
</tr>
<tr>
<td class="form1" align="right"><strong>Industry Segment:</strong></td>
<td class="form2"><asp:DropDownList ID="ddlIndSegment" runat="server" CssClass="fields" /></td>
</tr>
<tr>
<td class="form1" align="right"><strong>Member Type:</strong></td>
<td class="form2"><asp:DropDownList ID="ddlMemberType" runat="server" CssClass="fields" /></td>
</tr>
<tr>
<td class="form1" align="right"><strong>Member Rep only:</strong></td>
<td class="form2"><asp:CheckBox ID="cbxMemberRep" runat="server" /></td>
</tr>
<tr>
<td class="form1" align="right"><strong>Board Only:</strong></td>
<td class="form2"><asp:CheckBox ID="cbxBoardOnly" runat="server" /></td>
</tr>
<tr>
<td colspan="2" align="right">
<asp:ImageButton ID="btnSearch" runat="server" ImageUrl="/RadControls/images/bu_search.jpg" />
</td>
</tr>
</table>
</td>
<td> </td>
<td valign="top" width="50%">
<%--split the table here--%>
<table border="0" cellpadding="3" cellspacing="1"
style="width: 98%; margin-left: 0px;">
<tr>
<td class="form1" align="right"><strong>Suspended Only:</strong></td>
<td class="form2"><asp:CheckBox ID="cbxSuspended" runat="server" /></td>
</tr>
<tr>
<td class="form1" align="right"><strong>Active Only:</strong></td>
<td class="form2"><asp:CheckBox ID="cbxActiveOnly" runat="server" /></td>
</tr>
<tr>
<td class="form1" align="right"><strong>Allow Other Members To See My Info Only:</strong></td>
<td class="form2"><asp:CheckBox ID="cbxAllowOtherMembers" runat="server" /></td>
</tr>
<tr>
<td class="form1" align="right"><strong>State:</strong></td>
<td class="form2"><asp:DropDownList ID="ddlState" runat="server" CssClass="fields" /></td>
</tr>
<tr>
<td class="form1" align="right"><strong>By Special Level:</strong></td>
<td class="form2"><asp:DropDownList ID="ddlSpecialLevel" runat="server" CssClass="fields" /></td>
</tr>
<tr>
<td class="form1" align="right"><strong>Sort by:</strong></td>
<td class="form2">
<asp:DropDownList ID="ddlSortBy" runat="server" CssClass="fields">
<asp:ListItem Value="CompanyName">Company</asp:ListItem>
<asp:ListItem Value="FirstName">First Name</asp:ListItem>
<asp:ListItem Value="LastName">Last Name</asp:ListItem>
<asp:ListItem Value="MemberCategoryId">Membership Type</asp:ListItem>
<asp:ListItem Value="IndustrySegmentId">Industry Segment</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table border="0" cellpadding="3" cellspacing="1" width="100%">
<tr>
<td><asp:Literal ID="litTotalCount" runat="server" /></td><td align=left class="form3">
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">Export To Excel</asp:LinkButton>
<small>* Click on the column to SORT</small></td></tr>
</table>
<asp:Repeater ID="rptList" runat="server">
<HeaderTemplate>
<table class="sortable" border="0" cellpadding="3" cellspacing="1" width="100%">
<tr>
<td align="left" valign="top" class="form1"><b>Company</b></td>
<td align="left" valign="top" class="form1"><b>First Name</b></td>
<td align="left" valign="top" class="form1"><b>Last Name</b></td>
<td align="left" valign="top" class="form1"><b>Email</b></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td class="form2" align="left" valign="top"><asp:HyperLink ID="hlCompany" runat="server" CssClass="link"></asp:HyperLink></td>
<td class="form2" align="left" valign="top"><asp:HyperLink ID="hlFirstName" runat="server" CssClass="link"></asp:HyperLink></td>
<td class="form2" align="left" valign="top"><asp:HyperLink ID="hlLastName" runat="server" CssClass="link"></asp:HyperLink></td>
<td class="form2" align="left" valign="top"><asp:HyperLink ID="hlEmail" runat="server" CssClass="link"></asp:HyperLink> </td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<asp:GridView ID="GridView2" runat="server">
</asp:GridView>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"><br />
<UC:Paging Id="ctlPaging" runat="server" />
</asp:PlaceHolder>
<%-- <div align="center">
<br /><UC:Paging Id="ctlPaging" runat="server" />
</div>--%>
</asp:Content>
Sorry but this is a better explanation of the issue
Exporting from c#.net I am getting a problem I have a form that when I export to excel I ge the following <div></div> I have data in the datagrid but not in excel I am just getting <div></div>
And this is the function that I am using
void ExportToExcel3()
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GridView2.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
}
I am populating the datagrid prior to the export. This is the line of code. It's funny I create a new webform just with this section of code and the export worked.
Do you think there's a problem with the datarepeater that I have in the page that is causing the conflict.
MemberList list = MemberDB.GetMembers(sql, m_page, m_RecordPerPage, out count, _state);
this.GridView2.DataSource = list;
this.GridView2.DataBind();
That's not the sequence at all- it's just not how asp.net and the web work.
You don't fill the grid during the load phase: you retrieve the data and set it as the datasource for the table, but the grid (actually a repeater) isn't filled yet. That doesn't happen until the databinding phase. After the databinding phase (during the render phase) the page with the databound repeater is finally sent by the server to the browser. At this point all your server-side stuff is disposed.
Now the browser can finally show the page with the big "Export to Excel" button which the user can click. Again: the server is already destroying all the data you worked so hard to build. When the user clicks your button, a brand new request is created and a brand new page will be sent back to the browser. You have to load all your data into the grid again.
I found the solution to my problem. Thank you all for contributing. On the Load_Page Event I had the binding inside of an if !postback.