想修改DataGrid中TextBox的值,可是修改不了,老是读取原来的值.请各位高手帮忙修改一下吧!<asp:TemplateColumn HeaderText="Top10">
<ItemStyle HorizontalAlign="Center" Width="10%"></ItemStyle>
<ItemTemplate>
<asp:textbox id="txtTop10" Runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Top10") %>' Width="20px">
</asp:textbox>
<asp:LinkButton runat="server" Text="修改" CommandName="Top10" CausesValidation="false" ID="lbtnTop10"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>代码:
if ( e.CommandName == "Top10" )
{
int productid = int.Parse(e.Item.Cells[0].Text.ToString());
int top10=int.Parse(((TextBox)this.HeadlinesGrid.Items[e.Item.ItemIndex].Cells[9].FindControl("txtTop10")).Text.ToString());
// int top10=5;
try
{
myiproduct.UpdateTop10(productid,top10);
HeadlinesGrid.CurrentPageIndex=0;
Bindcouter();
BindGrid();
}
<ItemStyle HorizontalAlign="Center" Width="10%"></ItemStyle>
<ItemTemplate>
<asp:textbox id="txtTop10" Runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Top10") %>' Width="20px">
</asp:textbox>
<asp:LinkButton runat="server" Text="修改" CommandName="Top10" CausesValidation="false" ID="lbtnTop10"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>代码:
if ( e.CommandName == "Top10" )
{
int productid = int.Parse(e.Item.Cells[0].Text.ToString());
int top10=int.Parse(((TextBox)this.HeadlinesGrid.Items[e.Item.ItemIndex].Cells[9].FindControl("txtTop10")).Text.ToString());
// int top10=5;
try
{
myiproduct.UpdateTop10(productid,top10);
HeadlinesGrid.CurrentPageIndex=0;
Bindcouter();
BindGrid();
}
解决方案 »
- 文章分段怎么实现?
- 在.net 2.0里面弄FCK时。网页出现了 HTTP 错误 404 - Not Found
- js脚本中遇到的问题,关于无刷新的
- 请问你们做会员系统会使用membership吗
- 征集类似土豆,迅雷等网站导航效果的制作方案!!!
- 急急急!FreeTextBox中输入的内容为什么获取不到
- 如何在客户端实现自定义纸张?(xp/2000)
- 还是设置DATAGRID中加入的HyperLink的TEXT的问题,我按大家方法做了,还是不行,请指教,有代码!
- 如何让datagrid显示数据时只显示在一个固定区域。给个例子吧
- 如何在asp.net在抛掷异常,比如在button_click时,检测文本框。
- 关于超接列的问题,急!
- 大家进来帮我看看是什么原因?
,DataGrid只是個表示的東東而已,你改後又沒去改動數據源
{
// 在此处放置用户代码以初始化页面
_ID= (Request.Params["ID"] ==null)?-1:( int.Parse(Request.Params["ID"]));
_SearchText= (Request.Params["SearchText"] ==null)?"":( Request.Params["SearchText"]); if (!IsPostBack)
{
TxtSearch.Text=_SearchText; CreateDocTree(); DropDownList1.Items.Insert(0,new ListItem("所有列表","-1"));
DropDownList1.SelectedIndex=DropDownList1.Items.IndexOf(DropDownList1.Items.FindByValue(_ID.ToString()));
}
} /// <summary>
/// 生成树形下拉菜单
/// </summary>
private void CreateDocTree()
{
DataTable dtblCategory = new DataTable( "Category" );
// Create Columns
DataColumn dcolColumn = new DataColumn( "CategoryID", typeof( Int32 ) );
dtblCategory.Columns.Add( dcolColumn );
dcolColumn = new DataColumn( "FatherID", typeof( Int32 ) );
dtblCategory.Columns.Add( dcolColumn );
dcolColumn = new DataColumn( "Name", typeof( string ) );
dtblCategory.Columns.Add( dcolColumn );
ICategory myicategory=new ICategory();
DataTable dv = myicategory.ProductCategoryGetlist(0);
int nodecounts=dv.Rows.Count;
for(int i=0;i<nodecounts;i++)
{
int id=Convert.ToInt32(dv.Rows[i][0].ToString());
int hifid=Convert.ToInt32(dv.Rows[i][1].ToString());
string foldername=dv.Rows[i][2].ToString(); DataRow drowItem = dtblCategory.NewRow();
drowItem[ "CategoryID" ] = id;
drowItem[ "FatherID" ] = hifid;
drowItem[ "Name" ] = foldername;
dtblCategory.Rows.Add( drowItem ); LoadSubFolder(ref dtblCategory,id,1); DropDownList1.DataSource = dtblCategory.DefaultView;
DropDownList1.DataTextField="Name";
DropDownList1.DataValueField="CategoryID";
DropDownList1.DataBind();
}
}
private void LoadSubFolder(ref DataTable dtblCategory , int hifolderid,int deep)
{
ICategory myicategory=new ICategory();
DataTable dv = myicategory.ProductCategoryGetlist(hifolderid);
int nodecounts=dv.Rows.Count;
if(nodecounts!=0)
{
for(int i=0;i<nodecounts;i++)
{
int id=Convert.ToInt32(dv.Rows[i][0].ToString());
int hifid=Convert.ToInt32(dv.Rows[i][1].ToString());
string foldername=dv.Rows[i][2].ToString(); DataRow drowItem = dtblCategory.NewRow();
drowItem[ "CategoryID" ] = id;
drowItem[ "FatherID" ] = hifid; string strdeep=""; for(int j=0;j<deep;j++)
{
strdeep = strdeep + " ";
}
drowItem[ "Name" ] = strdeep+foldername;
dtblCategory.Rows.Add( drowItem );
LoadSubFolder(ref dtblCategory,id,deep+1);
}
}
}
protected void Bindcouter()
{
IDAL.IProduct myiproduct=new IProduct();
int recordCount = myiproduct.GetList(_ID,_SearchText,true);
pager1.RecordCount=recordCount;
}
protected void BindGrid()
{
IDAL.IProduct myiproduct=new IProduct();
DataTable mytable=new DataTable();
mytable = myiproduct.GetList(_ID,_SearchText,true,pager1.PageSize,pager1.CurrentPageIndex);
HeadlinesGrid.DataSource = mytable;
HeadlinesGrid.DataBind();
pager1.CustomInfoText="记录总数:<font color=\"blue\"><b>"+pager1.RecordCount.ToString()+"</b></font>";
pager1.CustomInfoText+=" 总页数:<font color=\"blue\"><b>"+pager1.PageCount.ToString()+"</b></font>";
pager1.CustomInfoText+=" 当前页:<font color=\"red\"><b>"+pager1.CurrentPageIndex.ToString()+"</b></font>";
}private void pager1_PageChanged(object src, Wuqi.Webdiyer.PageChangedEventArgs e)
{
Bindcouter();
pager1.CurrentPageIndex=e.NewPageIndex;
BindGrid();
} private void HeadlinesGrid_ItemCommand_1(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
IProduct myiproduct=new IProduct();
if ( e.CommandName == "Delete" )
{
int productid = int.Parse(e.Item.Cells[0].Text.ToString());
try
{
myiproduct.ProductDelete(productid);
this.lblMsg.Text="删除成功!";
HeadlinesGrid.CurrentPageIndex=0;
Bindcouter();
BindGrid();
}
catch
{
this.lblMsg.Text="删除失败!";
}
}
else if ( e.CommandName == "Hot" )
{
int productid = int.Parse(e.Item.Cells[0].Text.ToString());
try
{
myiproduct.UpdateHot(productid);
HeadlinesGrid.CurrentPageIndex=0;
Bindcouter();
BindGrid();
}
catch
{
this.lblMsg.Text="失败!";
}
} else if ( e.CommandName == "Spe" )
{
int productid = int.Parse(e.Item.Cells[0].Text.ToString());
try
{
myiproduct.UpdateSpe(productid);
HeadlinesGrid.CurrentPageIndex=0;
Bindcouter();
BindGrid();
}
catch
{
this.lblMsg.Text="失败!";
}
}
else if ( e.CommandName == "New" )
{
int productid = int.Parse(e.Item.Cells[0].Text.ToString());
try
{
myiproduct.UpdateNew(productid);
HeadlinesGrid.CurrentPageIndex=0;
Bindcouter();
BindGrid();
}
catch
{
this.lblMsg.Text="失败!";
}
} else if ( e.CommandName == "Lack" )
{
int productid = int.Parse(e.Item.Cells[0].Text.ToString());
try
{
myiproduct.UpdateLack(productid);
HeadlinesGrid.CurrentPageIndex=0;
Bindcouter();
BindGrid();
}
catch
{
this.lblMsg.Text="失败!";
}
}
else if ( e.CommandName == "Top10" )
{
int productid = int.Parse(e.Item.Cells[0].Text.ToString());
int top10=int.Parse(((TextBox)this.HeadlinesGrid.Items[e.Item.ItemIndex].Cells[9].FindControl("txtTop10")).Text.ToString());
// int top10=5;
try
{
myiproduct.UpdateTop10(productid,top10);
HeadlinesGrid.CurrentPageIndex=0;
Bindcouter();
BindGrid();
}
catch
{
this.lblMsg.Text="失败!";
}
}
}
{
Bindcouter();
pager1.CurrentPageIndex=e.NewPageIndex;
BindGrid();
}这个是干什么滴
ShowFooter="false" AllowPaging="True" PageSize="15" BorderColor="#B8B4A3" BorderWidth="1px">//要把DataKeyField用主键<asp:TemplateColumn HeaderText="街道名称">
<ItemStyle HorizontalAlign="left"></ItemStyle>
<ItemTemplate>
<asp:Label id=NameLabel runat="server" Width="100" Text='<%# DataBinder.Eval(Container.DataItem, "s_name") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id=edit_Name runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "s_name") %>'>
</asp:TextBox>
<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" Display="Dynamic" ControlToValidate="edit_Name">不可以空白</asp:RequiredFieldValidator>
</EditItemTemplate>
</asp:TemplateColumn><asp:EditCommandColumn ButtonType="LinkButton" UpdateText="更新" HeaderText="编辑" CancelText="取消" EditText="编辑">
<ItemStyle Wrap="False" Width="70px"></ItemStyle>
</asp:EditCommandColumn>
if (!Page.IsPostBack)
{
BindGrid();
}
void BindGrid()
{
//绑定 你的DataGrid
}
private void InitializeComponent()
{
this.GridAdmin.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.GridAdmin_EditCommand);
this.GridAdmin.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.GridAdmin_UpdateCommand);
this.Load += new System.EventHandler(this.Page_Load); }
private void GridAdmin_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
int id = Convert.ToInt32(GridAdmin.DataKeys[e.Item.ItemIndex].ToString());
yksl.BLL.street street = new yksl.BLL.street();
TextBox CurrentTextBox;
CurrentTextBox = (TextBox)e.Item.FindControl("edit_Name");
you_update(.........
//写个方法更新数据库
BindGrid();//重新绑
}