请问如何在取得DateGrid 中TextBox中的值 如果第9列應該是Cells[8]吧你把出錯信息貼出來看一下吧 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ((TextBox)DataGrid.Cells[2].FindControl("TextBox1")).Text; Html: <asp:BoundColumn DataField="GiftShipperSL" HeaderText="发货人"></asp:BoundColumn> <asp:BoundColumn DataField="GiftConsignee" HeaderText="收货人"></asp:BoundColumn> <asp:BoundColumn DataField="ShipmentDate" HeaderText="日期" DataFormatString="{0:yyyy-MM-dd}"></asp:BoundColumn> <asp:EditCommandColumn ButtonType="PushButton" UpdateText="更新" CancelText="取消" EditText="编辑"></asp:EditCommandColumn> <asp:ButtonColumn Text="删除" ButtonType="PushButton" CommandName="Delete"></asp:ButtonColumn>CS: string strGiftShipperSL=((TextBox)e.Item.Cells[7].Controls[0]).Text.ToString(); string strGiftConsignee=((TextBox)e.Item.Cells[8].Controls[0]).Text.ToString(); // string strDate=((TextBox)e.Item.Cells[9].Controls[0]).Text.ToString(); // TextBox strdate=((TextBox)e.Item.Cells[9].Controls[0]); string strdate=((TextBox)e.Item.FindControl("ShipmentDate")).Text;现在发现就是取日期的时候有问题 下面的sql就会有问题 把ItemDataBond事件裡的代碼貼出來 下面是update代码 第九列放的是日期protected void DataGrid1_Update(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { try { string conStr = ConfigurationSettings.AppSettings["connString"]; string strid = e.Item.Cells[1].Text.ToString();// string strid = DataGrid1.DataKeys[e.Item.ItemIndex].ToString(); string strdb = e.Item.Cells[2].Text.ToString(); string strLayout = e.Item.Cells[3].Text.ToString(); string strGiftSale = e.Item.Cells[4].Text.ToString(); string strGiftName = e.Item.Cells[5].Text.ToString(); string strGiftNum = ((TextBox)e.Item.Cells[6].Controls[0]).Text.ToString(); string strGiftShipperSL=((TextBox)e.Item.Cells[7].Controls[0]).Text.ToString(); string strGiftConsignee=((TextBox)e.Item.Cells[8].Controls[0]).Text.ToString(); // string strDate=((TextBox)e.Item.Cells[9].Controls[0]).Text.ToString(); // TextBox strdate=((TextBox)e.Item.Cells[9].Controls[0]); string strdate=((TextBox)e.Item.FindControl("ShipmentDate")).Text; string updateCmd="UPDATE Gift_shipment set GiftName='"+strGiftName+"',LayoutName='"+strLayout+"',GiftSale='"+strGiftSale+"',ShipmentDate='"+strDate+"',GiftNum='"+strGiftNum+"',GiftShipperSL='"+strGiftShipperSL+"',GiftConsignee='"+strGiftConsignee+"' where id ='"+strid+"'"; SqlConnection con=new SqlConnection(conStr); SqlCommand myCommand=new SqlCommand(updateCmd,con); myCommand.Connection.Open(); myCommand.ExecuteNonQuery(); DataGrid1.EditItemIndex=-1; GetSqlData(); } catch { Response.Write("<script>alert('修改失败!')</script>"); } 晕,你日期不进行转换怎么存储到数据表。一个是time型,一个是字符串型。 DateTime MyDate;MyDate = Convert.ToDateTime(txtInput.Text); 现在的问题是重Datagrid取值就有问题 string strDate=((TextBox)e.Item.Cells[9].Controls[0]).Text.ToString(); 这样取好象不行呀 string strDate=((TextBox)e.Item.Cells[8].FindControl("TextBox1")).Text.ToString(); 对,第九烈应该是Cells[8],你把9换成8应该就没问题。 换了都不行啊! 我直接给StrDate赋了植就可以写入数据库了 上面的写法不行 AssemblyInfo.CS使用问题 怎么在web页面修改Web.config的内容 如何一次性删除多个SQL2005的存储过程(图形操作和SQL语句都可以)? 读取sitemapnode的roles属性的值 Web中如何调用SaveDialog 请教一个asp的session问题? 网站运行一段时间后我后台登陆后就登陆不了,重启服务器就好了,请问是怎么回事啊?? 页面自动滚到到获取焦点的控件位置的功能 asp.net 布局? 如何在客户端脚本中使用DataGrid中EditItemTemplate中的TextBox? 高手进asp.net .net调用存储过程的问题?
<asp:BoundColumn DataField="GiftConsignee" HeaderText="收货人"></asp:BoundColumn>
<asp:BoundColumn DataField="ShipmentDate" HeaderText="日期" DataFormatString="{0:yyyy-MM-dd}"></asp:BoundColumn>
<asp:EditCommandColumn ButtonType="PushButton" UpdateText="更新" CancelText="取消" EditText="编辑"></asp:EditCommandColumn>
<asp:ButtonColumn Text="删除" ButtonType="PushButton" CommandName="Delete"></asp:ButtonColumn>CS: string strGiftShipperSL=((TextBox)e.Item.Cells[7].Controls[0]).Text.ToString();
string strGiftConsignee=((TextBox)e.Item.Cells[8].Controls[0]).Text.ToString();
// string strDate=((TextBox)e.Item.Cells[9].Controls[0]).Text.ToString();
// TextBox strdate=((TextBox)e.Item.Cells[9].Controls[0]);
string strdate=((TextBox)e.Item.FindControl("ShipmentDate")).Text;现在发现就是取日期的时候有问题 下面的sql就会有问题
protected void DataGrid1_Update(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
try
{
string conStr = ConfigurationSettings.AppSettings["connString"];
string strid = e.Item.Cells[1].Text.ToString();
// string strid = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
string strdb = e.Item.Cells[2].Text.ToString();
string strLayout = e.Item.Cells[3].Text.ToString();
string strGiftSale = e.Item.Cells[4].Text.ToString();
string strGiftName = e.Item.Cells[5].Text.ToString();
string strGiftNum = ((TextBox)e.Item.Cells[6].Controls[0]).Text.ToString();
string strGiftShipperSL=((TextBox)e.Item.Cells[7].Controls[0]).Text.ToString();
string strGiftConsignee=((TextBox)e.Item.Cells[8].Controls[0]).Text.ToString();
// string strDate=((TextBox)e.Item.Cells[9].Controls[0]).Text.ToString();
// TextBox strdate=((TextBox)e.Item.Cells[9].Controls[0]);
string strdate=((TextBox)e.Item.FindControl("ShipmentDate")).Text; string updateCmd="UPDATE Gift_shipment set GiftName='"+strGiftName+"',LayoutName='"+strLayout+"',GiftSale='"+strGiftSale+"',ShipmentDate='"+strDate+"',GiftNum='"+strGiftNum+"',GiftShipperSL='"+strGiftShipperSL+"',GiftConsignee='"+strGiftConsignee+"' where id ='"+strid+"'";
SqlConnection con=new SqlConnection(conStr);
SqlCommand myCommand=new SqlCommand(updateCmd,con);
myCommand.Connection.Open();
myCommand.ExecuteNonQuery();
DataGrid1.EditItemIndex=-1;
GetSqlData(); }
catch
{
Response.Write("<script>alert('修改失败!')</script>");
}
一个是time型,一个是字符串型。
MyDate = Convert.ToDateTime(txtInput.Text);