I want to add controls dynamically
Code:
.aspx
<body>
<form id="form1" runat="server">
<asp:Label ID="lbl1" Text="Personal Information" Font-Size="Large" ForeColor="White" runat="server" Width="854px" BackColor="SteelBlue" style="margin-top: 0px" Height="60px"> </asp:Label>
<div id="div1" runat="server">
<asp:Panel ID="panelPersonal" runat="server">
<div id="divreg" runat="server">
<table id="tbl" runat="server">
<tr>
<td class="style8"> Visa Number:</td>
<td class="style20"> <asp:TextBox ID="txtUser" Width="160px" runat="server"/></td>
<td class="style22"> Country Name:</td>
<td class="style23"> <asp:DropDownList ID="dropCountry" Width="165px" runat="server"></asp:DropDownList></td>
</tr>
<tr>
<td class="style22"> Type of Visa:</td>
<td class="style23"> <asp:DropDownList ID="dropVisa" Width="165px" runat="server"> </asp:DropDownList></td>
<td class="style22"> Type of Entry:</td>
<td class="style23"> <asp:DropDownList ID="dropEntry" Width="165px" runat="server"></asp:DropDownList></td>
</tr>
<tr>
<td class="style8"> Expiry Date</td>
<td class="style20">
<%--<BDP:BasicDatePicker ID="BasicDatePicker4" runat="server" onselectionchanged="BasicDatePicker2_SelectionChanged" AutoPostBack="True" />--%>
</td>
</tr>
</table>
</div>
</asp:Panel>
<asp:Button ID="addnewtext" runat="server" Text="Add" onclick="addnewtext_Click" width="76px" />
</div>
</form>
Here I am using User control
.ascx
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="AddVisaControl.ascx.cs" EnableViewState="false" Inherits="Pyramid.AddVisaControl" %>
<div id="divreg" runat="server">
<table id="tbl" runat="server">
<tr>
<td> Visa Number:</td>
<td><asp:TextBox ID="txtUser" Width="160px" runat="server"/></td>
<td> Country Name:</td>
<td><asp:DropDownList ID="dropCountry" Width="165px" runat="server"></asp:DropDownList></td>
</tr>
<tr>
<td> Type of Visa:</td>
<td><asp:DropDownList ID="dropVisa" Width="165px" runat="server"></asp:DropDownList></td>
<td> Type of Entry:</td>
<td><asp:DropDownList ID="dropEntry" Width="165px" runat="server"></asp:DropDownList></td>
</tr>
<tr>
<td> Expiry Date</td>
<td>
</td>
</tr>
</table>
</div>
.aspx.cs
Here is the problem If I click add button one row is added successfully but when I close and open again previously added rows also coming.
I think the problem is static int i = 0;
Any other way is there?
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
}
static int i = 0;
protected void addnewtext_Click(object sender, EventArgs e)
{
i++;
for (int j = 0; j <= i; j++)
{
AddVisaControl ac = (AddVisaControl)Page.LoadControl("AddVisaControl.ascx");
PlaceHolder1.Controls.Add(ac);
PlaceHolder1.Controls.Add(new LiteralControl("<BR>"));
}
}
This is what I am getting
This is what I want, Like below image I want to do
Any ideas? Thanks in advance
can you use a repeater /gridview control in the place of place holder control ,i think that is the best method for your situvation
I recommend this solution. It is different from the code you are using but still very easy.
You can use a Repeater control
<asp:Repeater ID="rpt1" runat="server">
<ItemTemplate>
user control code goes here but first put it in a div(example id - div1) with `style="display:none"`
</ItemTemplate>
</asp:Repeater>
on the server side you do this
rpt1.DataSource = Utils.GetRptTable(4); // will add the code 4 times but it will not be visible
rpt1.DataBind();
Later in javascript on the page you can find the first div with id div1 that has style - display:none and show it. That way you will show the next "row" with fields.
Edit 1
If you can add all your fields in the user control in a single <tr> you don't need a div with style= display:none. You will just have to add this class="GridBody" to your <tbody> - like: <tbody class="GridBody">
Then you do this to the row:
<tr class="GridRow" id="row1" style="display: none">
...
</tr>
and the javascript to show the row is:
function addRow() {
var body = $(".GridBody");
var indexOfNextRow = $('tr[class="GridRow"][hidden="false"]').length;
var tr = $(".GridBody tr")[indexOfNextRow];
tr.style.display = 'table-row';
tr.setAttribute('hidden', 'false');
}
Related
I have a C# ASP .net web form with one panel having many controls like text boxes and drop downs in a tabular column. User is allowed to enter data in these controls and when Copy button is pressed, all the contents of this panel should be copied to another panel on the same page having exactly same controls and columns whose enabled property is set to false
I am only getting the option of doing it like below
eg:-
Protected void Button_click ()
{
Panel2.textbox1.Text = Panel1.textbox1.Text;
Panel2.textbox2.Text = Panel1.textbox2.Text;
...
...
...
Panel2.textbox30.Text = Panel1.textbox30.Text;
which causes lot many lines of code and i feel its just not the good approach. Could you suggest any other alternatives or is it the only way?
My markup looks like this
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm5.aspx.cs" Inherits="AjaxToolkitTrial.WebForm5" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 100%;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="auto-style1">
<tr>
<td>
<asp:Panel ID="Panel1" runat="server">
<table class="auto-style1">
<tr>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Copy" />
</td>
</tr>
</table>
</asp:Panel>
</td>
<td>
<asp:Panel ID="Panel2" runat="server">
<table class="auto-style1">
<tr>
<td>
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</asp:Panel>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Thanks in advance..
you can consider this as hint, but the name of controls should be same in both the panels to identify it.. see the below pseudocode which may help you
foreach(Control c in Panel1.Controls)
{
var control = Panel2.Controls.AsEnumerable().Where(p => p.name = c.name).select();
Textbox txt = control as TextBox;
c.Text = txt.Text;
}
you should create all of panel2 controls dynamiclly.
Like
TextBox txt1 = new TextBox()
TextBox txt2 = new TextBox()
Panel2.Controls.Add(txt1);
Panel2.Controls.Add(txt2);
...
...
This is not good approach too. So you should create a loop and create your all controls in a loop.
Alternatively you can think for using a UserControl..
What i would do in this instance is use some form of templated control like a repeater, then when the copy button is pressed, i copy the data as a new row in the datasource, and then rebind the repeater to the new data - you will then have a copy of both the data and the control in two rows in the repeater.
I am trying to hide and show text boxes by radio button using jquery. I can show and hide text boxes but the error is I have a drop-down list. When I select drop-down value the page getting refreshed. After page refresh I am unable to do hiding and showing of text boxes. I have update panel for ajax. Why I am unable to hide and show text boxes after page refresh? Here is my source code. Please help me.
<%# Page Title="" Language="C#" MasterPageFile="~/Home.Master" AutoEventWireup="true" CodeBehind="ExperienceADD.aspx.cs" Inherits="Manjilas.WebForm31"%>
<%# Register Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit" tagPrefix="ajax" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<head>
<script src="Scripts2/jquery-1.7-vsdoc.js"></script>
<script src="Scripts2/jquery-1.7.js"></script>
<script src="Scripts2/jquery-1.7.min.js"></script>
<script type="text/javascript">
$(function () {
$('input[name="type"]').on('click', function () {
if ($(this).val() == 'Experienced') {
$('#txtcomp').Show();
$('#txtfrom').Show();
$('#txtto').Show();
} else {
$('#txtcomp').hide();
$('#txtcomp').hide();
$('#txtfrom').hide();
$('#txtto').hide();
}
});
});
</script>
</head>
<div class="container-fluid">
<div class="row-fluid">
<div class="well span5 center login-box">
<div class="alert alert-info">
<b><font size="4">ADD EXPERIENCE DETAILS</font></b>
</div>
<form id="form1" runat="server">
<asp:UpdatePanel ID="updatepanel1" runat="server"><ContentTemplate>
<div>
<ajaxToolkit:ToolkitScriptManager runat="server">
</ajaxToolkit:ToolkitScriptManager>
<asp:UpdatePanel ID="updatepanel2" runat="server"></asp:UpdatePanel>
<fieldset>
<table class="ui-accordion">
<tr>
<td align="left" class="style2">
MachID</td>
<td align="left">
<%-- <div class="input-prepend" title="Select Country Name">--%>
<asp:DropDownList ID="ddid" runat="server" AutoPostBack="True"
onselectedindexchanged="ddid_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
<tr>
<td align="left" class="style2">
<asp:Label ID="Empcode" runat="server" Text="EmpCode"></asp:Label>
<td align="left">
<asp:TextBox ID="txtname" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td align="left" class="style2">
</td>
<td align="left">
<input type="radio" name="type" value="Fresher" />Fresher
<input type="radio" name="type" value="Experienced" />Experienced
</td>
</tr>
<tr>
<td align="left" class="style2">
Company</td>
<td align="left">
<div class="input-prepend" title="Autogenerated District ID" data-rel="tooltip">
<asp:TextBox ID="txtcomp" runat="server" TextMode="SingleLine"></asp:TextBox>
</td>
</tr>
<tr>
<td align="left" class="style2">
From Date</td>
<td align="left">
<div class="input-prepend" title="Enter District Name" data-rel="tooltip">
<asp:TextBox ID="txtfrom" runat="server" TextMode="SingleLine"></asp:TextBox>
<ajax:CalendarExtender ID="Calendarextender1" TargetControlID ="txtfrom" Format="dd/MM/yyyy" runat="server"></ajax:CalendarExtender>
</td>
</tr>
<tr>
<td align="left" class="style2">
To Date</td>
<td align="left">
<div class="input-prepend" title="Enter District Name" data-rel="tooltip">
<asp:TextBox ID="txtto" runat="server" TextMode="SingleLine"></asp:TextBox>
<ajax:CalendarExtender ID="Calendarextender2" TargetControlID ="txtto" Format="dd/MM/yyyy" runat="server"></ajax:CalendarExtender>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td align="left">
<asp:Button ID="Button1" class="btn-primary" runat="server" Text="Add"
Height="36px" Width="74px" onclick="Button1_Click" />
<asp:Button ID="Button2" class="btn-primary" runat="server" Text="Cancel"
Height="36px" Width="74px" PostBackUrl="~/districtDetails.aspx" />
</td>
</tr>
<tr>
<td class="style2">
</td>
<td align="left">
<asp:Label ID="Label2" runat="server" ForeColor="Red"></asp:Label>
</td>
</tr>
</table>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</fieldset>
</form>
</div><!--/span-->
</div><!--/row-->
</div>
</div>
</asp:Content>
It's because you're using an UpdatePanel, it will refresh everything inside it's <ContentTemplate>, which in your case has input[name="type"] inside it.
Because it's refreshed, the on('click', function() { isn't binding the current radiobutton with the name="type" anymore, thus make the click never triggered after you select one item inside the dropdown, what you need is to wrap the UpdatePanel only for things that you want to be refreshed or changed only, like this for your case:
<asp:UpdatePanel ID="updatepanel1" runat="server">
<ContentTemplate>
<tr>
<td align="left" class="style2">
MachID
</td>
<td align="left">
<asp:DropDownList ID="ddid" runat="server" AutoPostBack="True"
onselectedindexchanged="ddid_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
<tr>
<td align="left" class="style2">
<asp:Label ID="Empcode" runat="server" Text="EmpCode"></asp:Label>
</td>
<td align="left">
<asp:TextBox ID="txtname" runat="server"></asp:TextBox>
</td>
</tr>
</ContentTemplate>
</asp:UpdatePanel>
Other Way
Use the jQuery on click selector, you just need to change
$('input[name="type"]').on('click', function () {
if ($(this).val() == 'Experienced') {
$('#txtcomp').show();
$('#txtfrom').show();
$('#txtto').show();
}
too
$('.ui-accordion').on('click', 'input[name="type"]', function () {
if ($(this).val() == 'Experienced') {
$('#txtcomp').show();
$('#txtfrom').show();
$('#txtto').show();
}
The show function is k senstive. Try this:
$('#txtcomp,#txtfrom,#txtto').show();
I have added DropDownList1 in Default.aspx page my ASP.Net project, and I have the below code in Default.cs:
if(DropDownList1.SelectedItem.ToString()=="")
I got this error:
Error 2 The name 'DropDownList1' does not exist in the current context
Edit:
In *.cs:
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
string username = Login1.UserName;
string pwd = Login1.Password;
var connstring = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString; ;
var conn = new SqlConnection(connstring);
conn.Open();
SqlCommand command;
if(DropDownList1.SelectedItem.ToString()=="")
command = new SqlCommand("Select [ID] from [Inspector] WHERE [ID] =" + username + " AND [Password] ='" + pwd + "';", conn);
SqlDataReader dr = command.ExecuteReader();
if (dr.Read())
{
if (dr[0].ToString() == username)
{
Session["UserAuthentication"] = username;
Session.Timeout = 1;
Response.Redirect("MainInspector.aspx");
}
else
{
Session["UserAuthentication"] = "";
}
}
}
In *.aspx:
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent" >
<style type="text/css">
.style1
{
height: 26px;
}
</style>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent" >
<h2>
الصفحة الرئيسية</h2>
<p>
الرجاء تسجيل الدخول:</p>
<p>
<asp:Login ID="Login1" runat="server"
FailureText="لم يتم تسجيل دخولك، الرجاء المحاولة ثانية."
LoginButtonText="تسجيل الدخول" onauthenticate="Login1_Authenticate"
PasswordLabelText="كلمة المرور:" RememberMeText="تذكرني في المرات القادمة"
TitleText="نسترعي إنتباهك أن كلمة المرور حساسة لحالة الأحرف"
UserNameLabelText="رقم الهوية:">
<LayoutTemplate>
<table cellpadding="1" cellspacing="0" style="border-collapse:collapse;">
<tr>
<td>
<table cellpadding="0">
<tr>
<td align="center" colspan="2">
نسترعي إنتباهك أن كلمة المرور حساسة لحالة الأحرف</td>
</tr>
<tr dir="rtl">
<td align="right">
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">رقم الهوية:</asp:Label>
</td>
<td>
<asp:TextBox ID="UserName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server"
ControlToValidate="UserName" ErrorMessage="User Name is required."
ToolTip="User Name is required." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right" class="style1">
<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">كلمة المرور:</asp:Label>
</td>
<td class="style1">
<asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server"
ControlToValidate="Password" ErrorMessage="Password is required."
ToolTip="Password is required." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td colspan="2">
تسجيل الدخول بوصفك:<br />
<asp:CheckBox ID="RememberMe" runat="server" Text="تذكرني في المرات القادمة" />
<br />
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color:Red;">
<asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
<br />
</td>
</tr>
<tr>
<td align="right" colspan="2">
<asp:Button ID="LoginButton" runat="server" CommandName="Login"
Text="تسجيل الدخول" ValidationGroup="Login1" />
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>فاحص</asp:ListItem>
<asp:ListItem>مُدرب</asp:ListItem>
<asp:ListItem>مُتدرب</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</table>
</td>
</tr>
</table>
</LayoutTemplate>
</asp:Login>
</p>
</asp:Content>
You need to check your markup to confirm that the ID matches i.e.
<asp:DropDownList id="DropDownList1".....
If it is a web application the designer.cs file could be messed up as this has the reference within it.
Something like this:
protected global::System.Web.UI.WebControls.DropDownList DropDownList1;
If it is missing try adding the above.
Such errors might appear when the markup in the .aspx page (or .ascx control) is not well formed. In cases where the markup is bad, when you add a new control its declaration is not added in the designer file and leads to this error.
If this is the case, one common trick to fix this is to cut and paste the markup of the control. This way you re-add the control and make Visual Studio to re-add the declaration of the control in the designer file.
DropDownList1 does not exist in the current context
The solution for me was to place the DropDownList outside of of the LoginView.
Try moving the DropDownList to another section of your page and see if this works.
i have added modalPopupExtender in my Page and inside that i am calling another page in Iframe. And on button Click i am doing some processing, i just want to know how can i close the modalPopUpExtender on submit click of that button.
My code is -
<cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" DynamicServicePath="" Enabled="True" PopupControlID="PP"
TargetControlID="btnCounceller" BackgroundCssClass="modalBackground"
CancelControlID="btnclose">
</cc1:ModalPopupExtender>
<asp:Panel ID="PP" runat="server" BackColor="white" Height="200px" Width="350px">
<table class="style1">
<tr>
<td> </td>
<td>
<iframe ID="ff" runat="server" frameborder="0" src="Order.aspx" style="width:350px; height:200px;"></iframe>
</td>
<td>
<asp:Button ID="btnclose" runat="server" Text="X" />
</td>
</tr>
</table>
</asp:Panel>
and My Order.aspx Contains
<table>
<tr>
<td>First Name :</td>
<td><asp:TextBox ID="txtName" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Mobile:</td>
<td><asp:TextBox ID="txtMobile" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td><asp:Label ID="lblMessage" runat="server" Visible="false"></asp:Label></td>
</tr>
<tr>
<td></td>
<td><asp:Button ID="btnSubmit" runat="server" Text="Submit"
onclick="btnSubmit_Click" /></td>
</tr>
</table>
Now i just want to close my modalPopUp on click of Submit Button from IFrame
<asp:Panel ID="PP" runat="server" BackColor="white" Height="200px" Width="350px">
<table class="style1">
<tr>
<td> </td>
<td>
<asp:Button ID="btnclose" runat="server" Text="X" OnClick="btnclose_Click" />
</td>
<td>
<iframe ID="ff" runat="server" frameborder="0" src="Order.aspx" style="width:350px; height:200px;"></iframe>
</td>
</tr>
</table>
</asp:Panel>
Protected void btnclose_Click(Object sender, EventArgs e)
{
response.redirect("yourpage.aspx");
}
You can use jQuery as below
$("#btnSubmit").click(function() {
$("#<%= btnclose.ClientID %>").click();
});
This will fire click event of your cancel control btnclose for the modal popup extender on clicking btnSubmit from your iframe. You need to find and replace the actual ID for your iframe button btnSubmit.
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.