本文介绍了必须将带有'ImageButton'类型的控件'ctl00_ImageButton2'放在带有runat = server的表单标记内。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的cs文件是....
my cs file is....
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;
using System.Text;
using System.Drawing;
public partial class approvedreports : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["hospitalConnectionString"].ToString());
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string str = "select s_no, Rejected, first_name, second_name, bill_number, Labname, testname, approval_date from testrates where Rejected = 'R'";
gvDetails11.DataSource = getdata(str);
gvDetails11.DataBind();
}
}
private DataTable getdata(string str)
{
SqlCommand cmd = new SqlCommand(str, con);
DataTable dt = new DataTable();
SqlDataAdapter adp = new SqlDataAdapter();
adp.SelectCommand = cmd;
adp.Fill(dt);
con.Close();
return dt;
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
string str1 = "select s_no, Rejected, first_name, second_name, bill_number, Labname, testname, approval_date from testrates where Rejected = 'R'";
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
using (StringWriter sw = new StringWriter())
{
HtmlTextWriter hw = new HtmlTextWriter(sw);
//To Export all pages
gvDetails11.AllowPaging = false;
this.getdata(str1);
gvDetails11.HeaderRow.BackColor = System.Drawing.Color.White;
foreach (TableCell cell in gvDetails11.HeaderRow.Cells)
{
cell.BackColor = gvDetails11.HeaderStyle.BackColor;
}
foreach (GridViewRow row in gvDetails11.Rows)
{
row.BackColor = Color.White;
foreach (TableCell cell in row.Cells)
{
if (row.RowIndex % 2 == 0)
{
cell.BackColor = gvDetails11.AlternatingRowStyle.BackColor;
}
else
{
cell.BackColor = gvDetails11.RowStyle.BackColor;
}
cell.CssClass = "textmode";
}
}
gvDetails11.RenderControl(hw);
//style to format numbers to string
string style = @"<style> .textmode { } </style>";
Response.Write(style);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
}
}
}
我的aspx文件是..
my aspx file is..
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="approvedreports.aspx.cs" Inherits="approvedreports" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<style type="text/css">
.Gridview
{}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
</br>
</br>
</br>
</br>
</br>
</br>
<form id="fm" runat="server">
<asp:Panel ID="Panel1" runat="server">
<asp:GridView ID="gvDetails11" runat ="server"
AutoGenerateColumns="False" CssClass="Gridview" HeaderStyle-BackColor="#61A6F8"
ShowFooter="True" HeaderStyle-Font-Bold="true" HeaderStyle-ForeColor="White"
HorizontalAlign="Center" DataKeyNames="bill_number" Width="998px"
>
<Columns>
<asp:BoundField DataField="s_no" HeaderText="Serial Number"></asp:BoundField>
<asp:BoundField DataField="first_name" HeaderText="First Name"></asp:BoundField>
<asp:BoundField DataField="second_name" HeaderText="Second Name">
</asp:BoundField>
<asp:BoundField DataField="bill_number" HeaderText="Bill Number">
</asp:BoundField>
<asp:BoundField DataField="Labname" HeaderText="Labname"></asp:BoundField>
<asp:BoundField DataField="testname" HeaderText="Test Name"></asp:BoundField>
<asp:BoundField DataField="approval_date" HeaderText="Date Of Apporval">
</asp:BoundField>
</Columns>
<HeaderStyle BackColor="#61A6F8" Font-Bold="True" ForeColor="White"></HeaderStyle>
</asp:GridView>
</asp:Panel>
<table align = "center">
<tr>
<td>
<asp:ImageButton ID="ImageButton2" runat="server" Height="52px"
ImageUrl="~/Images/downlaod.jpg" onclick="ImageButton1_Click" Width="75px"></asp:ImageButton>
</td>
</tr>
</table>
</form>
</asp:Content>
我的主页是..
and my master page is ..
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder id="head" runat="server">
<link type="text/css" href="css/ui-lightness/jquery-ui-1.8.19.custom.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.19.custom.min.js"></script>
<style type="text/css">
.style1
{
width: 174px;
text-align: left;
background-color: #F5F5F5;
}
.style2
{
width: 100%;
}
.sortable:hover {
cursor: pointer;
cursor: hand;
}
.style4
{
font-family: "Gill Sans MT Condensed";
font-size: x-large;
color: #663300;
}
.style5
{
width: 477px;
height:98px;
}
.style6
{
height: 98px;
}
.style7
{
color: #CC3300;
}
.style8
{
color: #CC9900;
}
.style9
{
font-family: "Gill Sans MT Condensed";
font-size: xx-large;
color: #663300;
}
.style10
{
width: 480px;
height: 100px;
}
</style>
</head>
<body>
<div>
<table class="style2" style="height: 98px; background-color: #CCCCCC">
<tr>
<td style="text-align: left; background-image: removed('/WebSite14/Images/Stethoscope-Doctor1.jpg');">
class="style5">
<img alt="" class="style10" src="Images/Stethoscope-Doctor1.jpg" /></td>
<td style="text-align: center; " class="style6">
<span class="style9"><span class="style7">Medical</span> <span class="style8">Bill</span>
<span class="style7">Reimbursement</span></span><span class="style4">
<br />
</span>
<asp:Label
ID="Label4" runat="server" Text="Portal" CssClass="style4">
</td>
<td style="text-align: right;" class="style6">
<asp:Label ID="Label5" runat="server" style="font-size: x-large; font-weight: 700; font-family: 'Monotype Corsiva'; color: #FFFFFF;"
Text="Welcome">
<asp:ImageButton ID="ImageButton2" runat="server" src="Images/logout.png"
Height="22px" Width="80px" onclick="ImageButton2_Click" />
</td>
</tr>
</table>
<table width="100%">
style="height: 436px"><tr><td class="style1" valign="top">
<br />
<br />
<br />
<br />
<br />
<asp:Button ID="ED" runat="server" BorderStyle="None" Text="Employee Details"
class="sortable" style="font-family: Algerian; background:rgba(4,41,64,0.3);"
Width="150px" onclick="ED_Click" />
<br />
<br />
<asp:Button ID="OutDoor" runat="server" BorderStyle="None" Text="OutDoor Details"
class="sortable" style="font-family: Algerian; background:rgba(4,41,64,0.3);"
Width="150px" onclick="OutDoor_Click" />
<br />
<br />
<asp:Button ID="Bills" runat="server" BorderStyle="None" Text="Upload Bills"
class="sortable" style="font-family: Algerian; background:rgba(4,41,64,0.3);"
Width="150px" onclick="Bills_Click" />
<br />
<br />
<asp:Button ID="Test" runat="server" BorderStyle="None" Text="Test Details"
class="sortable" style="font-family: Algerian; background:rgba(4,41,64,0.3);"
Width="150px" onclick="Test_Click" />
<br />
<br />
<asp:Button ID="Download" runat="server" BorderStyle="None" Text="Download Form"
class="sortable" style="font-family: Algerian; background: rgba(4,41,64,0.3);"
Width="150px" onclick="Download_Click" Height="21px" />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
</td><td>
<asp:Panel ID="panel1" runat="server" Height="1000" ScrollBars="Auto">
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</td></tr></table>
</div>
</body>
</html>
kindly help me guys..
kindly help me guys..
推荐答案
<asp:ImageButton ID="ImageButton2" runat="server" src="Images/logout.png"
Height="22px" Width="80px" onclick="ImageButton2_Click" />
In asp u have to use ImageUrl instead of
In asp u have to use ImageUrl instead of
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="Images/logout.png"
Height="22px" Width="80px" onclick="ImageButton2_Click" />
这篇关于必须将带有'ImageButton'类型的控件'ctl00_ImageButton2'放在带有runat = server的表单标记内。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!