datagrid1的datasource是 datasource1,
解决方案 »
- 自定义控件
- 知道本机文件路径,如何上传到web服务器的一个文件夹里,不使用上传控件
- asp.net用,还是不用,控件好?
- Button控件里面的OnCommand属性和OnClick属性,有什么区别?
- 绑定事件的问题!!!高手请进!!
- 又要有劳各位大师,敢问如何在html让网页一加载,就运行一个应用程序
- iis .netframework已经安装了,为什么我的网站在这台机器上仍然不能运行?输入127.0.0.1,显示出来default.aspx的源代码了
- ben 的PopupBox修改了一下。但没有保留原始的。现在网站上下不下来了,谁有原始的工程rar 借用一下
- 问一个在安装VS.NET2003时,安装MSDN2003的问题.
- 难难难难难难难难难难难难难难
- DataTable是否可以动态绑定ButtonColumn?是否可以添加一个不分列的空行?---help!!!
- 请教这样的数据比较为何不等?
private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
try
{
ds = (DataSet)Session["NowDS"];
DataRow rw = ds.Tables["contract"].Rows[e.Item.ItemIndex];
rw.Delete();
da.Update(ds,"contract");
bindNew(true);
ShowErrMsg("删除记录成功!");
}
catch
{
ShowErrMsg("删除记录失败,请重试!");
}
}
在datagrid的itencommand中
if e.commandName="Delete" then
'加入删除代码
end if
Sub MyDataGrid_Delete(ByVal Sender As Object, ByVal E As DataGridCommandEventArgs)End Sub
////////////////大家看 这个数据源怎么删除?////////////
string filename1 = Path.GetFileName(myFile.PostedFile.FileName) ;
//if(upfiles1.Rows.Find(filename)==null)
DataRow[] myrow=upfiles1.Select("FileName='"+filename1.ToString()+"'");
if(myrow.Length ==0)
{
int filelen = myFile.PostedFile.ContentLength;
string filetype = myFile.PostedFile.ContentType;
Stream fstream = myFile.PostedFile.InputStream;
byte[] filedata = new byte[filelen];
fstream.Read(filedata,0,filelen);
DataRow dr = upfiles1.NewRow();
dr[0] = filename1;
dr[1] = filetype;
dr[2] = filelen;
dr[3] = filedata;
dr[4] = wjm.Text .Trim();
dr[5] = zbh.Text.Trim();
dr[6] = "选址意见书";
dr[7] = TextBoxqz.Text.Trim();
upfiles1.Rows.Add( dr );
files.DataSource = upfiles1;
files.DataBind();
Dagrid1.DataSource=upfiles1;
Dagrid1.DataBind();
<Columns>
<asp:BoundColumn DataField="PersonId" HeaderText="用户编号"></asp:BoundColumn>
<asp:BoundColumn DataField="PersonName" HeaderText="用户名称"></asp:BoundColumn>
<asp:BoundColumn DataField="NationName" HeaderText="所在区域"></asp:BoundColumn>
<asp:BoundColumn DataField="FullName" HeaderText="所在省份"></asp:BoundColumn>
<asp:BoundColumn DataField="CityName" HeaderText="所在城市"></asp:BoundColumn>
<asp:BoundColumn DataField="CreateTime" HeaderText="注册时间"></asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<div align="center">
<button type="button" onclick="SelectHumanInfo('<%# DataBinder.Eval(Container,"DataItem.PersonId") %>')">查看</button>
</div>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
下面是我的代码
private void dtgJob_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
//引用job接口
Job job = (Job) new AppJob() ;
//删除成功与否的标记
bool bjob = false;
try
{
int iProjectID = Int32.Parse(e.Item.Cells[0].Text.ToString()); //获取ProjectID作为主键
bjob = job.deleteJob(iProjectID);//标志新增是否成功
}
catch (Exception ex)
{
SystemLog.WriteLog(sUserName, ex.Message.ToString());
this.Response.Redirect("../../Error.aspx?ErrMessage=" + ErrorMessage.DELETE_APPJOB_FAILED);
}
if (bjob)
{
//删除成功
this.Response.Redirect("DisplayJob.aspx");
}
else
{
Response.Write("<script language=javascript>alert('Delete Failed!');</script>");
}
}
<asp:datagrid id="dgrd" runat="server" DataKeyField="PersonId" AutoGenerateColumns="false" ShowFooter="True" OnItemCommand="ItemCommandHandler" ShowHeader="True" Width="100%">
2.添入删除列;有CommandName字段
<asp:ButtonColumn Text="删除" runat="server" CommandName="deleteinfo">3.加入函数
aspx.cs中:
public void ItemCommandHandler(object sender,DataGridCommandEventArgs e)
{
if (e.CommandName=="deleteinfo")
{
int index=dgrd.CurrentPageIndex;
int nPersonId=(int)dgrd.DataKeys[e.Item.ItemIndex];
string strConnection = ConfigurationSettings.AppSettings["SQLConnectionString"];
SqlConnection conn = new SqlConnection(strConnection);
conn.Open(); //打开数据库
String strcmd2="delete from Table1 where PersonId='"+nPersonId+"'";
SqlCommand cmd2=new SqlCommand(strcmd2,conn);
cmd2.ExecuteNonQuery();
}
}
=======================================
public void CreatTable(){
myConnectionlei=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["datalei"]);
SqlDataAdapter myCommandlei = new SqlDataAdapter("select FileName,FileType,FileLen,FileData,ffName,PrjID,PrjType,Prefix,[ID] from Accessories where [ID]<-1", myConnectionlei);
DataSet mydataset = new DataSet();
myCommandlei.Fill(mydataset, "Accessoriestable");
upfiles2 = myCommandlei;
upfiles1 = mydataset.Tables["Accessoriestable"];
}
==================================
private void ButPast_Click(object sender, System.EventArgs e)
{
if (upfiles1 == null)
{
CreatTable();
}
if( myFile.PostedFile.FileName != "" &&zbh.Text!=""&&wjm.Text!="" )
{
string filename1 = Path.GetFileName(myFile.PostedFile.FileName) ;
//if(upfiles1.Rows.Find(filename)==null)
DataRow[] myrow=upfiles1.Select("FileName='"+filename1.ToString()+"'");
if(myrow.Length ==0)
{
int filelen = myFile.PostedFile.ContentLength;
string filetype = myFile.PostedFile.ContentType;
Stream fstream = myFile.PostedFile.InputStream;
byte[] filedata = new byte[filelen];
fstream.Read(filedata,0,filelen);
DataRow dr = upfiles1.NewRow();
dr[0] = filename1;
dr[1] = filetype;
dr[2] = filelen;
dr[3] = filedata;
dr[4] = wjm.Text .Trim();
dr[5] = zbh.Text .Trim();
dr[6] = "选址意见书";
dr[7] = TextBoxqz.Text.Trim();
upfiles1.Rows.Add( dr );
files.DataSource = upfiles1;
files.DataBind();
Dagrid1.DataSource=upfiles1;
Dagrid1.DataBind();
Page.RegisterStartupScript("script", "<script>alert('附件粘贴成功');</script>");
}
}
else
{
//Page.RegisterStartupScript("script", "<script>alert('请选择文件!');</script>");
Page.RegisterStartupScript("script", "<script>alert('文件、文件名、总编号不能为空');</script>"); }
}
==================================