我要做查询会议记录这个功能。会议记录有时候上传附件,有时候不上传,我在数据表里用MR_PATH来记录附件的存储目录。那么当我查询的时候,有附件的会议记录就显示下载附件这个控件(ImageButton),没有附件的会议记录就不显示这个控件。
查询按钮的代码如下:
protected void imbtnfind_Click(object sender, ImageClickEventArgs e)
{
string fromdate = TBfromdate.Text.ToString();
string todate = TBtodate.Text.ToString();
string ConnectionString = ConfigurationManager.AppSettings["ConnectionString"];
string sql = "select mr_id,mr_date,mr_time,mr_compere,mr_pl from ims_meetingreport where mr_date between '"+
fromdate+"' and '"+todate+"'";
SqlDataAdapter ada = new SqlDataAdapter(sql, ConnectionString);
DataSet ds = new DataSet();
ada.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
visible();
}
protected void visible()
{
string ConnectionString = ConfigurationManager.AppSettings["ConnectionString"];
string mr_id = "select mr_id from ims_meetingreport";
SqlDataAdapter sda = new SqlDataAdapter(mr_id, ConnectionString);
DataSet das = new DataSet();
sda.Fill(das);
int i;
for (i = 1; i < das.Tables[0].Rows.Count; i++)
{
string id=GridView1.Rows[i].Cells[0].Text.ToString();
string sql = "select mr_path from ims_meetingreport where mr_id='"+id+"'";
SqlDataAdapter ada = new SqlDataAdapter(sql, ConnectionString);
DataSet ds = new DataSet();
ada.Fill(ds);
string txtsql = ds.Tables[0].Rows[0][0].ToString();
//string imbtndownload = ((ImageButton)GridView1.Rows[i].Cells[0].Controls[0]).Text.ToString();
if (txtsql != "")
{
((ImageButton)GridView1.Rows[i].Cells[0].Controls[0]).Visible = true;
}
else
{
((ImageButton)GridView1.Rows[i].Cells[0].Controls[0]).Visible = false;
//((ImageButton)GridView1.Columns[4]).Visible = false;
}
}
}
红色部分表示下载控件那个图标按钮,但是程序运行到这里的时候,会报错“说指定参数已超出有效值的范围”,请高手指点下应该怎么样解决这个问题,我不清楚((ImageButton)GridView1.Rows[i].Cells[0].Controls[0]).Visible = false这里写得是否正确,如果不正确,应该怎么改?
查询按钮的代码如下:
protected void imbtnfind_Click(object sender, ImageClickEventArgs e)
{
string fromdate = TBfromdate.Text.ToString();
string todate = TBtodate.Text.ToString();
string ConnectionString = ConfigurationManager.AppSettings["ConnectionString"];
string sql = "select mr_id,mr_date,mr_time,mr_compere,mr_pl from ims_meetingreport where mr_date between '"+
fromdate+"' and '"+todate+"'";
SqlDataAdapter ada = new SqlDataAdapter(sql, ConnectionString);
DataSet ds = new DataSet();
ada.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
visible();
}
protected void visible()
{
string ConnectionString = ConfigurationManager.AppSettings["ConnectionString"];
string mr_id = "select mr_id from ims_meetingreport";
SqlDataAdapter sda = new SqlDataAdapter(mr_id, ConnectionString);
DataSet das = new DataSet();
sda.Fill(das);
int i;
for (i = 1; i < das.Tables[0].Rows.Count; i++)
{
string id=GridView1.Rows[i].Cells[0].Text.ToString();
string sql = "select mr_path from ims_meetingreport where mr_id='"+id+"'";
SqlDataAdapter ada = new SqlDataAdapter(sql, ConnectionString);
DataSet ds = new DataSet();
ada.Fill(ds);
string txtsql = ds.Tables[0].Rows[0][0].ToString();
//string imbtndownload = ((ImageButton)GridView1.Rows[i].Cells[0].Controls[0]).Text.ToString();
if (txtsql != "")
{
((ImageButton)GridView1.Rows[i].Cells[0].Controls[0]).Visible = true;
}
else
{
((ImageButton)GridView1.Rows[i].Cells[0].Controls[0]).Visible = false;
//((ImageButton)GridView1.Columns[4]).Visible = false;
}
}
}
红色部分表示下载控件那个图标按钮,但是程序运行到这里的时候,会报错“说指定参数已超出有效值的范围”,请高手指点下应该怎么样解决这个问题,我不清楚((ImageButton)GridView1.Rows[i].Cells[0].Controls[0]).Visible = false这里写得是否正确,如果不正确,应该怎么改?
GridView1.Rows[i].Cells[0].Controls[0] 再通过调试功能的quickwatch查看这个是不是有
这种处理建议你放到OnRowCreated OnRowDataBound 中处理
你的这个control不是在表头和表脚有的
判断IMAGEBUTTON,使不可见
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
function OpenDate(control)
{
Url = "../../Calendar.aspx?control="+control;
window.open(Url,'_blank','width=400,height=270');
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="z-index: 100; left: 0px; position: absolute; top: 0px;
height: 544px" width="800">
<caption>
例会记录查询</caption>
<tr>
<td style="width: 800px; height: 10%;">
<asp:Label ID="Label1" runat="server" Style="z-index: 100; left: 0px; position: static;
top: 0px" Text="请选择查询时间范围:从"></asp:Label>
<asp:TextBox ID="TBfromdate" runat="server" Width="120px"></asp:TextBox>
<a onmouseover="window.status='选择日期';return true;" onmouseout="window.status='';return true;"
href="javascript:OpenDate('TBfromdate')" title="选择时间">
<img src="../../Image/button/选择时间.gif" alt="选择时间" id="IMG1" onclick="return IMG1_onclick()"
style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none;" /></a>
<asp:Label ID="Label2" runat="server" Style="z-index: 100; left: 0px; position: static;
top: 0px" Text="到"></asp:Label>
<asp:TextBox ID="TBtodate" runat="server" Width="120px"></asp:TextBox>
<a onmouseover="window.status='选择日期';return true;" onmouseout="window.status='';return true;"
href="javascript:OpenDate('TBtodate')" title="选择时间">
<img src="../../Image/button/选择时间.gif" alt="选择时间" id="IMG2" onclick="return IMG1_onclick()"
style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none;" /></a>
<asp:ImageButton ID="imbtnfind" runat="server" ImageUrl="~/Image/button/搜索.JPG" OnClick="imbtnfind_Click" /></td>
</tr>
<tr>
<td style="width: 800px; height: 82%;">
<asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="#3366CC"
BorderStyle="None" BorderWidth="1px" CellPadding="4" Style="z-index: 100; left: 16px;
position: absolute; top: 96px" AutoGenerateColumns="False">
<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<RowStyle BackColor="White" ForeColor="#003399" />
<PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
<Columns>
<asp:BoundField DataField="mr_id" HeaderText="记录编号" />
<asp:BoundField DataField="mr_date" HeaderText="开会日期" />
<asp:BoundField DataField="mr_compere" HeaderText="例会主持人" />
<asp:BoundField DataField="mr_time" HeaderText="记录上传时间" />
<asp:BoundField DataField="mr_pl" HeaderText="记录上传人" />
<asp:TemplateField HeaderText="是否存在附件">
<ItemTemplate>
<asp:ImageButton ID="imbtndownload" runat="server" ImageUrl="~/Image/button/下载附件.JPG"
OnClick="imbtndownload_Click" Visible="False" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="查看详细记录">
<ItemTemplate>
<asp:ImageButton ID="imbtnlook" runat="server" ImageUrl="~/Image/button/查看.JPG" OnClick="imbtnlook_Click" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
<tr>
<td style="height: 8%">
<asp:ImageButton ID="imbtntoexcel" runat="server" ImageUrl="~/Image/button/导入EXCEL.jpg"
Style="left: 547px; position: relative; top: 0px" /></td>
</tr>
</table>
</div>
</form>
</body>
</html>
这是前台页面的代码,请说得详细一点,我主要就是不知道模板中的那个ImageButton要怎么表达!
判断IMAGEBUTTON,使不可见;
我也知道要这么做,就是不知道代码要怎么写,麻烦高手指点一下,谢了!
判断IMAGEBUTTON,使不可见;
我也知道要这么做,就是不知道代码要怎么写,麻烦高手指点一下,谢了!
//string imbtndownload = ((ImageButton)GridView1.Rows[i].Cells[0].Controls[0]).Text.ToString();
if (txtsql.length >0 )
{
((ImageButton)GridView1.Rows[i].Cells[5].FindControl("imbtndownload").Visible=true;
}
else
{
((ImageButton)GridView1.Rows[i].Cells[5].FindControl("imbtndownload").Visible = false;
}
循环中相应代码修改string txtsql = ds.Tables[0].Rows[i][5].ToString();
//string imbtndownload = ((ImageButton)GridView1.Rows[i].Cells[0].Controls[0]).Text.ToString();
if (txtsql.length >0 )
{
(ImageButton)GridView1.Rows[i].Cells[5].FindControl("imbtndownload").Visible=true;
}
else
{
(ImageButton)GridView1.Rows[i].Cells[5].FindControl("imbtndownload").Visible = false;
}
上面的括号不匹配,这里改好了