要实现的功能是:遍历datagrid的时候,把text值取到,更新到数据库中。
或者有什么更好的方法,可以使用服务端控件,当点击+ 或- 按钮时,控件的值会相应的发生改变!
请大家多多帮忙!谢谢! 代码如下:
<asp:TemplateColumn HeaderText="数  量">
  <headerstyle wrap="False" Width="80px" HorizontalAlign="Center"></headerstyle>
  <ItemStyle HorizontalAlign="Right"></ItemStyle>
  <ItemTemplate>
     <input id="ct_<%# DataBinder.Eval(Container.DataItem,"ShoppingCartID")%>" name="txtNum" type=text value='<%# DataBinder.Eval(Container.DataItem,"BuyCount")%>' size="3">
     <input id="btnAdd_<%# DataBinder.Eval(Container.DataItem,"ShoppingCartID")%>" name="btnAdd" class="caclbt" type=button value="+" onclick='Javascript:UpdateCount(<%# DataBinder.Eval(Container.DataItem,"ShoppingCartID")%>,1);'>
     <input id="btnRed_<%# DataBinder.Eval(Container.DataItem,"ShoppingCartID")%>" name="btnRed" class="caclbt" type=button value="-" onclick='Javascript:UpdateCount(<%# DataBinder.Eval(Container.DataItem,"ShoppingCartID")%>,0);'>
   </ItemTemplate>
</asp:TemplateColumn>

解决方案 »

  1.   

    for(int i=0;i < WL_WZBM.Items.Count;i++)
    {
    string    UP_OID  = WL_WZBM.DataKeys[i].ToString();        //得到每一行的OID
    TextBox    TDJ    = (TextBox)WL_WZBM.Items[i].FindControl("DJ");
    }
      

  2.   

    楼上的方法可以,第2个利用button的commandname,以及datagrid的itemcommand事件来实现
      

  3.   

    我这个是在DATAGRID中的第一行列设置了模板列,放了一个CHECKBOX,在外部放了一个BUTTON,再CLICK事件里写的
    private void btnDelete_Click(object sender, System.EventArgs e)
    {
    string selectedstring = "";
    foreach(DataGridItem dgi in dgUserInfo.Items)
    {
    for(int i=0;i<dgi.Cells[0].Controls.Count;i++)
    {
    if(dgi.Cells[0].Controls[i].GetType().ToString()=="System.Web.UI.WebControls.CheckBox")
    {
    if(((CheckBox)dgi.Cells[0].Controls[i]).Checked==true)
    {
    selectedstring += dgUserInfo.DataKeys[dgi.ItemIndex].ToString() + ",";
    }
    }
    }
    }
    if(selectedstring!="")
    {
    bool result=true;
    selectedstring = selectedstring.Substring(0,selectedstring.Length-1);
    string[] arrselected = selectedstring.Split(',');
    for(int i=0;i<arrselected.Length;i++)
    {
    if(arrselected[i].Trim()!="")
    {
    result=Enroll.DeleteUser(Int32.Parse(arrselected[i]));
    p.DeleteSelfPage(Int32.Parse(arrselected[i]));
    }
    }
    if(result)
    {
    RegisterStartupScript("Succeed","<script>alert('用户删除成功')</script>");

    }
    }
    BindData();
    }
    这是得到编号,删除记录
    这样也许不符合楼主的要求,只是我提出的一个方法,供楼主参考一下
      

  4.   

    如果用以上方法,必须设置控件的DataKeyField属性
      

  5.   

    现在就是因为控件的ID是构造出来,所以如果用服务器端控件的话,前台改变数量的脚本就会失效,所以在datagrid的FindControl是找不到那几个控件!
    或者大家介绍其它的方法,可以实现在我想要功能!
      

  6.   

    如果用以上方法,必须设置控件的DataKeyField属性