GridView1_RowCommand 事件取值问题

william_918 2010-02-26 05:58:01


怎么在GridView1_RowCommand中得到Lable1值 Lable里面存的是日期, Label1是个模板列,
我是想,当我点击 下载卡号时,生成Excel表格,数据库里面我需要那个日期(label1的值)
我怎么取都取不到

下面就是RowCommand方法
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "download")
{
string filename = "FileFlow";
int companyid = Convert.ToInt32(e.CommandArgument);
//string dtime = GridView1.SelectedRow.Cells[3].Text;

DataSet ds = MemberCard.GetExcelMemberCardByIDAndTime(companyid, dt);
GridView1.DataSource = ds;
GridView1.DataBind();
Export(GridView1, "excel", filename);
}
}
...全文
194 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
mail_ylei 2010-03-01
  • 打赏
  • 举报
回复

---------------------
aspx页面
---------------------
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand">
<Columns>
<asp:BoundField DataField="ID" DataFormatString="编号" />
<asp:TemplateField>
<ItemTemplate>
<asp:Label runat="server" ID="lbl1" Text='<%# Eval("CTime") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="Button1" runat="server" Text="Button" CommandName="download" CommandArgument='<%# Eval("ID") +","+ Eval("CTime")%>'/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
---------------------
cs文件:
---------------------
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "download")
{
string[] strs = e.CommandArgument.ToString().Split(',');
if (strs.Length == 2)
{
int company_id = Convert.ToInt32(strs[0]);
string dt = strs[1];
//.....
}

}
}
---------------------
william_918 2010-03-01
  • 打赏
  • 举报
回复
加分没问题,我给你们说情况,题的情况,
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "download")
{
string filename = "FileFlow";
int company_id = Convert.ToInt32(e.CommandArgument);

//在这个里面不仅要得到company_id 的值,还要得到Label1的值,现在的问题就是怎么得到Label1的值,
company_id的值已经得到。

DataSet ds = MemberCard.GetExcelMemberCardByIDAndTime(companyid, dt);
GridView1.DataSource = ds;
GridView1.DataBind();
Export(GridView1, "excel", filename);
}
}
spark_wu 2010-03-01
  • 打赏
  • 举报
回复
CommandArgument 多绑定一个值
tan124 2010-03-01
  • 打赏
  • 举报
回复
DataRowView rowItem = (DataRowView)e.Row.DataItem;
duncannjm 2010-03-01
  • 打赏
  • 举报
回复
if (e.CommandName == "download")
{
GridViewRow gvrow = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
//获取被点击的linkButton所在的GridViewRow
int index = gvrow.RowIndex; //获取到行索引 RowIndex

Label lbl=(Label)Data_GV.Rows[index].FindControl("存放日期Label控件的ID");
if (lbl != null)//如果找到该控件
{
string dtime = lbl.Text;//赋值
}
else//要是找不到
{
}
}
SqlDataAdapter 2010-02-26
  • 打赏
  • 举报
回复
加点分再告诉你,呵呵
william_918 2010-02-26
  • 打赏
  • 举报
回复
3楼的大哥,protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Select")
{
string id = GridView1.DataKeys[Convert.ToInt32(e.CommandArgument)].Value.ToString();
Response.Write(id);
}
}
你说的这个是能得到值,("Select") 这一个控件只能绑定id,但是我需要得到的是另外一列的值(Label1它是模板列) 要怎么得到Label1的值?
wuyq11 2010-02-26
  • 打赏
  • 举报
回复
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Select")
{
string id = GridView1.DataKeys[Convert.ToInt32(e.CommandArgument)].Value.ToString();
Response.Write(id);
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
if(e.Row.RowIndex == GridView1.EditIndex)
{
DataRowView rowItem = (DataRowView)e.Row.DataItem;

}
}
}
happy664618843 2010-02-26
  • 打赏
  • 举报
回复
CommandArgument 绑定label中的值就可以
大飞飞虫 2010-02-26
  • 打赏
  • 举报
回复
你把Lable的值写到Lable.text的同时,往 download button的CommandArgument同时写一份,到时候直接取e.CommandArgument不就好了

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧