漫漫技术人生路

C#

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  234 随笔 :: 0 文章 :: 30 评论 :: 8 引用

公告

2006年10月24日 #

  for (int i = 0; i <e.Values.Keys.Count; i++)
        {

            string a = e.Values[i].ToString();//detailview中取值
        }
      

 protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        //GridViewRow selectRow = GridView1.SelectedRow;
        //string strId = selectRow.Cells[0].Text;
        //Response.Write(strId);
        //Response.End();
    }

在ing中 GridViewRow selectRow = GridView1.Rows[e.newselectIndex]

TextBox tb = (TextBox)con.FindControl("TextBox1");
  
  但con的值为null,这样后续的语句也不可能执行了。问题出在哪里呢?
  
  经过一番搜索,在forums.asp.net中找到了答案,以下引用的是bitmask的说法:
  ...becasue the Content controls themselves dissapear after the master page rearranges the page. You can use the ContentPlaceHolders, or the
on the MasterPage if there are no INamingContainers between the form and the control you need.   
  所以以上的代码应该改成:
  
  TextBox tb = (TextBox)PreviousPage.Master.FindControl("ContentPlaceHolder1").FindControl("TextBox1"); 
  


protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {

 

        GridViewRow row = GridView1.Rows[e.NewSelectedIndex];
                if (row.RowState == DataControlRowState.Selected)
        {
            this.Label3.Text = row.Cells[1].Text.ToString();
           this.txt1.Text ="你好";
        }

 

 protected void DetailsView1_ModeChanging(Object sender, System.Web.UI.WebControls.DetailsViewModeEventArgs e)
  {
    if (e.CancelingEdit == true)
    {
      Response.Redirect("GridViewMasterDetailsInsertPage_cs.aspx");
    }


protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e)
    {
        if (e.Exception != null)
        {
            ErrorMessageLabel.Text = "Failed to DELETE due to foreign key contstraint on the table.  You may only delete rows

which have no related records.";
            e.ExceptionHandled = true;
        }
    }

posted @ 2006-10-24 15:43 javaca88 阅读(257) 评论(0) 编辑

 在grid view控件中经常会遇到选择行的问题,怎么才能获得当前行呢?以下为该问题的解决方法:

protected void Button1_Click1(object sender, EventArgs e)
    {
        
        Button bt=(Button)sender;
        DataControlFieldCell dv=(DataControlFieldCell)bt.Parent;
        GridViewRow gvr=(GridViewRow)dv.Parent;
        index = gvr.RowIndex;
    }

Button1为girdview中的一个按钮空间,DataControlFieldCell dv为该控件所属的单元格,bt.Parent为获得他的父空间,  GridViewRow gvr=(GridViewRow)dv.Parent 获得所在行,  index = gvr.RowIndex取得行索引。

posted @ 2006-10-24 14:01 javaca88 阅读(216) 评论(0) 编辑

1.从四楼开始对前一楼的习作进行批改,建议大家使用“引用”格式,并将前一楼的错误用“颜色”标出

2.英译中

We ' re often told that the world is tethering on the brink of destruction . But is this really the case ?

答案刷黑可见,先自己翻译再看,革命靠自觉

我们经常被告知世界处于毁灭的边缘。但事实真是这样吗?

3.学习以下句型,要铭记于心啊!

We ' re often told that...

But is this really the case ?

posted @ 2006-10-24 12:52 javaca88 阅读(104) 评论(0) 编辑

posted @ 2006-10-24 12:51 javaca88 阅读(265) 评论(0) 编辑

使用 ChangeMode 方法以编程方式在编辑、插入和只读模式间切换 DetailsView 控件。此方法还将 CurrentMode [ http://msdn2.microsoft.com/zh-cn/library/system.web.ui.webcontrols.detailsview.currentmode.aspx ] 属性更新为指定模式。下表列出了不同的模式值。

 

模式

说明

DetailsViewMode.Edit

DetailsView 控件处于编辑模式,这样用户就可以更新记录的值。

DetailsViewMode.Insert

DetailsView 控件处于插入模式,这样用户就可以向数据源中添加新记录。

DetailsView.ReadOnly


DetailsView 控件处于只读模式,这是通常的显示模式。

下面的代码示例演示如何使用 ChangeMode 方法在每次用户导航到另一条记录时将 DetailsView 控件返回到只读模式。

C#
<%@ Page language="C#" %>

<script runat="server">

  void CustomerDetailView_PageIndexChanged(Object sender, EventArgs e)
  {
    // By default, if the DetailsView control is in edit mode and
    // user navigates to another page, the DetailsView control
    // remains in edit mode. In this example, the ChangeMode 
    // method is used to put the DetailsView control in read-only  
    // mode whenever the user navigates to another record.
      CustomerDetailView.ChangeMode(DetailsViewMode.ReadOnly);
  }

</script>

<html>
  <body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView ChangeMode Example</h3>
                
        <asp:detailsview id="CustomerDetailView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogenerateeditbutton="true"  
          autogeneraterows="true"
          allowpaging="true"
          OnPageIndexChanged="CustomerDetailView_PageIndexChanged"
          runat="server">
               
          <fieldheaderstyle backcolor="Navy"
            forecolor="White"/>
                    
        </asp:detailsview>
        
        <!-- This example uses Microsoft SQL Server and connects  -->
        <!-- to the Northwind sample database. Use an ASP.NET     -->
        <!-- expression to retrieve the connection string value   -->
        <!-- from the web.config file.                            -->
        <asp:SqlDataSource ID="DetailsViewSource" runat="server" 
          ConnectionString=
            "<%$ ConnectionStrings:NorthWindConnectionString%>"
          InsertCommand="INSERT INTO [Customers]([CustomerID],
            [CompanyName], [Address], [City], [PostalCode], [Country]) 
            VALUES (@CustomerID, @CompanyName, @Address, @City, 
            @PostalCode, @Country)"
          SelectCommand="Select [CustomerID], [CompanyName], 
            [Address], [City], [PostalCode], [Country] From 
            [Customers]">
        </asp:SqlDataSource>
    </form>
  </body>
</html>
posted @ 2006-10-24 12:41 javaca88 阅读(117) 评论(0) 编辑