日期:2014-05-19  浏览次数:20468 次

跪求GridView控件中的RowCommand事件的使用方法(孟子等大人们进啊,再解决不了我就失业了)
我在GRIDVIEW里放置了一列,在这个列里是读取数据库中IMAGEURL数据字段的,我把它绑定到了一个IMAGE控件上,这样在GRIDWIEW控件就可以显示出图片了,但我现在想还可以编辑修改,所以我在EditItemTempLatek中放置了三个控件,一个是FileUpLoad控件,用来读取图片路径,一个BUTTON控件,用来上传,还有一个TextBox控件,用来和数据库字段绑定更新,当点击上传按扭的时候,上传图片的同时,也把   TextBox控件中的图片路径改变。这样在更新的时候就应该成功了吧。现在的问题是GRIDVIEW控件中BUTTON控件的事件击要应用到   RowCommand,于是我就编写了一个
GridView1_RowCommand(object   sender,   GridViewCommandEventArgs   e)事件,可上传的时候,还需要FileUpLoad控件中选取的路径,而在RowCommand控件中确又不能用FidControl。。。。希望高手们帮帮我啊,我想一定是有办法可以解决的吧。


------解决方案--------------------
ding
------解决方案--------------------
Try

你可以定义一个类级别的变量,把FileUpLoad的路径值赋给它.
然后在GridView1_RowCommand(object sender, GridViewCommandEventArgs e)直接使用这个变量不就得到上传文件的路径了吗!!
------解决方案--------------------
顶!不能让lz失业
------解决方案--------------------
FindControl这个怎么会没有呢?应该是你自己程序没写对阿...
不过建议楼主可以换一种操作模式可能会比较简单;
------解决方案--------------------
.NET技术群12845737.
大量学习资料下载.

讨论VC/C#/ASP.NET/FLASH_AS技术

欢迎学习和技术人员加入
探讨技术,分享程序员生活.
------解决方案--------------------
给你编辑修改的例子

<%@ Page Language= "C# " AutoEventWireup= "true " Debug= "true " %>
<%@ Import Namespace= "System.Data " %>
<script runat= "server ">
string GetUserPhoto(object pathPhoto)
{
if (pathPhoto == DBNull.Value)
{
return " <img src= '../Images/none.gif '> ";
}
else
{
return " <img src= '../Upload/ " + pathPhoto.ToString() + " '> ";
}
}

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;

DropDownList clsName = (DropDownList)e.Row.FindControl( "uClassName ");
if (rowItem[ "ClassName "] != DBNull.Value)
{
clsName.Items.FindByText(rowItem[ "ClassName "].ToString()).Selected = true;
}

if (rowItem[ "Gender "] != DBNull.Value)
{

RadioButtonList oGender = (RadioButtonList)e.Row.FindControl( "uGender ");
oGender.SelectedIndex = (Convert.ToBoolean(rowItem[ "Gender "]) ? 0 : 1);
}
}
}
}

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "New ")
{
string StudentTitle = ((TextBox)GridView1.FooterRow.FindControl( "NewTitle ")).Text;
if (StudentTitle.Trim() == " ")
{
ErrorMsg.Text = "请输入姓名 ";
return;
}
string StudentBirthDay = ((TextBox)GridView1.FooterRow.FindControl( "NewBirthDay ")).Text;
bool StudentGender = ((RadioButtonList)
GridView1.FooterRow.FindControl( "NewGender ")).SelectedValue == "男 " ? true : false;
string StudentClassName = ((DropDownList)
GridView1.FooterRow.FindControl( "NewClassName ")).SelectedValue;
FileUpload oUpload = (FileUpload)GridView1.FooterRow.FindControl( "AddPhoto ");
String FileName = " ";
FileName = Guid.NewGuid().ToString( "D ") + System.IO.Path.GetExtension(oUpload.FileName);