dreammaster

天行健,君子以自强不息;地势坤,君子以厚德载物

博客园 首页 新随笔 联系 订阅 管理
  4 Posts :: 1 Stories :: 8 Comments :: 0 Trackbacks

公告

置顶随笔 #

摘要: NET Framework提供了多种序列化对象的方法,二进制,XML, SOAP,而在系统中应用往往使用对象序列化来暂存或缓存对象状态。阅读全文
posted @ 2007-03-14 15:51 梦幻天涯 阅读(600) 评论(1) 编辑

2007年3月14日 #

摘要: NET Framework提供了多种序列化对象的方法,二进制,XML, SOAP,而在系统中应用往往使用对象序列化来暂存或缓存对象状态。阅读全文
posted @ 2007-03-14 15:51 梦幻天涯 阅读(600) 评论(1) 编辑

2006年6月7日 #

 
在GridView的BoundField中定义的日期字段无法像DataGrid的一样定义格式。

<asp:BoundField DataField="SentDate" DataFormatString="{0:MM/dd/yyyy}" />

上面的代码不能将日期格式化为预期的效果, 必须将boundfield的HtmlEncode属性设置为false


<asp:BoundField DataField="SentDate" DataFormatString="{0:MM/dd/yyyy}" HtmlEncode="false"/>

这样就可以正确使用日期格式字符串了,对于货币,数字则不需要设置该属性.
posted @ 2006-06-07 13:20 梦幻天涯 阅读(809) 评论(0) 编辑

2006年5月19日 #

    在上一个学习随笔中我们可以利用DataKeyNames和DataKeys来进行GridView主键列的数据访问, 在后来试验中,我发现我们可以利用TemplateField来实现其他的数据访问.

<asp:TemplateField Visible="False">
     
<ItemTemplate>
          
<asp:Literal id="litUserName" runat="Server" Text='<%#Eval("UserName")%>'/>
     
</ItemTemplate>
</asp:TemplateField>

//后台实现

String userName = ((Literal)GridView1.SelectedRow.FindControl("litUserName")).Text;
    
     GridView的AutoGenerateSelectButton属性可以直接使表格实现选择,  如果不想多增加一列选择列, 我们可以利用TemplateField实现GridView的选择.

ASP.NET代码如下:

<asp:BoundField DataField="ObjectID" HeaderText="ID"/>
<asp:TemplateField>
    
<HeaderTemplate>
         Name
    
</HeaderTemplate>
    
<ItemTemplate>
         
<asp:LinkButton id="lbName" runat="Server" CommandName="Select">
            
<%#Eval("Name")%>
         
</asp:LinkButton>
    
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Status" HeaderText="Status"/>

同时要给GridView增加两个事件处理RowCreated, RowCommand
//RowCreated事件处理
void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
            if (e.Row.RowType == DataControlRowType.DataRow)
            {                ((LinkButton)e.Row.FindControl("lbName")).CommandArgument = e.Row.RowIndex.ToString();
            }
}
//RowCommand事件处理
void GridView1_RowCommand(object source, System.Web.UI.WebControls.GridViewCommandEventArgs e)
{
     GridView1.SelectedIndex = int.Parse(e.CommandArgument.ToString());
}

这样在点击名称时就可以同时进行选择,不必再利用选择列.
posted @ 2006-05-19 00:08 梦幻天涯 阅读(1831) 评论(3) 编辑

2006年5月9日 #

        最近在使用asp.net2.0中发现GridView与DataGrid在数据访问上的区别相当大,对于DataGrid访问每一行中的数据项通常有两种方法:
<asp:BoundColumn DataField="ID" Visible="False"/>


//后台处理

int id = int.Parse(Grid1.Items[index].Cells[0].Text);

//或采用

int id = (int)((DataRowView)Grid1.Items[index].DataItem).Row["ID"]);

      对于GridView两种方法均不见效, Visible=Flase的列不再Render,所以客户端不可能访问,对于DataItem,除了RowDataBound几个事件中可以使用, ViewState中不在保存DataItem,因此,对于GridView如果想知道某一行的值,不可以将其设为Visile=false,如果确实不 想在界面中显示这一列的值,可以用DataKeyNames和DataKeys结合完成一些特别的数据访问.
<asp:GridView id="GridView1" Runat="Server" DataKeyNames="ObjectID">



</asp:GridView>

//代码中处理选中行的id

int id = int.Parse(GridView1.DataKeys[GridView1.SelectedIndex].Value.ToString());

posted @ 2006-05-09 00:39 梦幻天涯 阅读(2261) 评论(4) 编辑

仅列出标题