web developer tips (65): 快速创建一个挂接SQL表的GridView


原文链接:How to quickly create a GridView that is hooked up to a SQL table? 通常,在一个页面的GridView绑定数据,是添加一个数据源,再通过一个向导挂接到数据源。这里介绍一个更快捷的方法来创建和挂接到数据源的GridView。 http://www.watch-life.net/visual-studio/quickly-create-a-gridview-that-is-hooked-up-to-a-sql-table.html 1、首先,如果没有数据源(datasource),你需要在服务器资源管理器(Server Explorer)添加一个。 2、完成上面一步,展开你想连接的表的节点,并找到想要挂接GridView的表。 3、最后,拖拽选中的表到webform,就这样......[阅读全文]

分类: Visual Studio | 没有评论 »

web developer tips (64): 在GridView中转换BoundField为TemplateField


原文地址:How to convert a GridView column from asp:BoundField to asp:TemplateField in Design View 假定你有个数据源SqlDataSource1 ,绑定了一个简单的查询语句,返回Customers表的详细信息。 http://www.watch-life.net/visual-studio/convert-a-gridview-column-from-boundfield-to-templatefield.html <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnectionString %>" SelectCommand="SELECT [FirstName], [LastName], [Email] FROM [Customers] ORDER BY [FirstName]"> </asp:SqlDataSource> 在Visual Studio里,在web ......[阅读全文]

分类: Visual Studio | 没有评论 »

web developer tips (53):在vs的设计视图编辑gridview的模板


原文地址:How to edit the templates for gridview in VS designer 通过模板的呈现,可以灵活地配置Gridview控件。下面的步骤将显示在Visual Studio 的设计视图如何编辑gridview的模板(template)。 http://www.watch-life.net/visual-studio/edit-the-templates-for-gridview-in-vs-designer.html 1、这里 GridView链接到了一个数据源Sqldatasource:Northwind.products,在配置sql 数据源时,选择“生成插入”、“更新”、“删除”语句。 2、单击gridview的智能任务(gridview 任务)标签,选中“启用编辑”项。 3、在字段列表选择一列名,单击“将此字段转换成TemplateFi......[阅读全文]

分类: Visual Studio | 没有评论 »

web developer tips (5):绑定ListView控件


原文地址:How to Databind a ListView control ListView 是Visual Studio 2008中一个新的控件,使用此控件可以很轻松的进行数据的插入、编辑、删除和排序,也可以在使用这个控件时通过用户定义模板来灵活地显示各种格式的数据。 下面的如何将ListView 绑定到一个SQLDataSource(sql数据源) 步骤: http://www.watch-life.net/visual-studio/how-to-databind-a-listview-control.html 1、从工具箱的数据标签里添加一个Listview控件, Visual Studio将会生成如下图所示的代码 2、为这个控件绑定一个SQLDataSource,在这里,我们复制一个NorthWind.mdf 数据......[阅读全文]

分类: Visual Studio | 1 条评论 »

让GridView中CheckBox列支持FireFox


在Asp.net中,可以通过模板列,在Gridview中实现CheckBox列的实现,相关的代码并不复杂,你可以参考这里,我抽取的部分代码如下: <script language=”javascript” type=”text/javascript”>    function selectAll(obj)    {         var theTable  = obj.parentElement.parentElement.parentElement;         var i;         var j = obj.parentElement.cellIndex;      &n......[阅读全文]

分类: Asp.net | 没有评论 »

在gridview和datagrid里设置列宽


无论是gridview还是datagrid,在绑定数据后,列宽都不是固定的,在设计时是没法设定的,只能通过绑定是触发的事件来重新设定。参考http://msdn2.microsoft.com/zh-cn/library/ms178296(VS.80).aspx 的解释.
gridview的代码:

protected int widestData;
protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
System.Data.DataRowView drv;
drv = (System.Data.DataRowView)e.Row.DataItem;
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (drv != null)
{
[...]

[阅读全文]

分类: Asp.net | 2 条评论 »

在GRIDVIEW中合并单元格


///   <summary>       ///   合并GridView列中相同的行       ///   </summary>       ///   <param   name=”GridView1″>GridView对象</param>       ///   <param   name=”cellNum”>需要合并的列</param>       public static void GroupRows(GridView GridView1, int cellNum)     {         int i = 0, rowSpanNum = 1;         while (i < GridView1.Rows.Count – 1)         {             GridViewRow gvr = GridView1.Rows[i];             for (++i; i < GridView1.Rows.Count; i++......[阅读全文]

分类: Asp.net | 没有评论 »