正在阅读:ASP.Net开发新手常见问题备忘录ASP.Net开发新手常见问题备忘录

2005-08-09 10:05 出处: 作者:JadyZhu 责任编辑:xietaoming

22.读取DataGrid控件TextBox值

foreach(DataGrid dgi in yourDataGrid.Items)
{
    TextBox tb = (TextBox)dgi.FindControl("yourTextBoxId");
    tb.Text....
}

23.在DataGrid中有3个模板列包含Textbox分别为 DG_ShuLiang (数量) DG_DanJian(单价) DG_JinE(金额)分别在5.6.7列,要求在录入数量及单价的时候自动算出金额即:数量*单价=金额还要求录入时限制为 数值型.我如何用客户端脚本实现这个功能?

  〖思归〗

   <asp:TemplateColumn HeaderText="数量">
  <ItemTemplate>
   <asp:TextBox id="ShuLiang" runat='server'
Text='<%# DataBinder.Eval(Container.DataItem,"DG_ShuLiang")%>' 
    onkeyup="javascript:DoCal()"
   />

   <asp:RegularExpressionValidator id="revS" runat="server"
ControlToValidate="ShuLiang" ErrorMessage="must be integer" ValidationExpression="^\d+$" />
  </ItemTemplate>
      </asp:TemplateColumn>

      <asp:TemplateColumn HeaderText="单价">
  <ItemTemplate>
   <asp:TextBox id="DanJian" runat='server'
Text='<%# DataBinder.Eval(Container.DataItem,"DG_DanJian")%>'
    onkeyup="javascript:DoCal()"
   />

  <asp:RegularExpressionValidator id="revS2" runat="server"
ControlToValidate="DanJian" ErrorMessage="must be numeric" ValidationExpression="^\d+(\.\d*)?$" />

  </ItemTemplate>
      </asp:TemplateColumn>

     <asp:TemplateColumn HeaderText="金额">
  <ItemTemplate>
   <asp:TextBox id="JinE" runat='server'
Text='<%# DataBinder.Eval(Container.DataItem,"DG_JinE")%>' />
  </ItemTemplate>
      </asp:TemplateColumn>

<script language="javascript">
function DoCal()
{
  var e = event.srcElement;
  var row = e.parentNode.parentNode;
  var txts = row.all.tags("INPUT");
  if (!txts.length || txts.length < 3)
 return;
 
  var q = txts[txts.length-3].value;
  var p = txts[txts.length-2].value;

  if (isNaN(q) || isNaN(p))
 return;

  q = parseInt(q);
  p = parseFloat(p);

  txts[txts.length-1].value = (q * p).toFixed(2);
}
</script>

24.datagrid选定比较底下的行时,为什么总是刷新一下,然后就滚动到了最上面,刚才选定的行因屏幕的关系就看不到了

page_load
page.smartNavigation=true

25.在Datagrid中修改数据,当点击编辑键时,数据出现在文本框中,怎么控制文本框的大小 ?

private void DataGrid1_ItemDataBound(obj sender,DataGridItemEventArgs e)
{
       for(int i=0;i<e.Item.Cells.Count-1;i++)
          if(e.Item.ItemType==ListItemType.EditType)
           {
                  e.Item.Cells[i].Attributes.Add("Width", "80px")
            }  
}

26.对话框

private static string ScriptBegin = "<script language=\"JavaScript\">";
private static string ScriptEnd = "</script>";

public static void ConfirmMessageBox(string PageTarget,string Content)
  {

   string ConfirmContent="var retValue=window.confirm('"+Content+"');"+"if(retValue){window.location='"+PageTarget+"';}";
  
   ConfirmContent=ScriptBegin + ConfirmContent + ScriptEnd;
  
   Page ParameterPage = (Page)System.Web.HttpContext.Current.Handler;
   ParameterPage.RegisterStartupScript("confirm",ConfirmContent);
   //Response.Write(strScript);
 
  }

键盘也能翻页,试试“← →”键

关注我们

最新资讯离线随时看 聊天吐槽赢奖品