DataGrid & GridView 按钮功能

VS2003只有DATAGRID,没有GRIDVIEW

DataGrid

#列印
DataGrid-TemplateColumn 样板资料行

aspx

<asp:TemplateColumn HeaderText="列印"><HeaderStyle Wrap="False" HorizontalAlign="Center" Width="5%"></HeaderStyle><ItemTemplate><asp:ImageButton id="btnPrint" runat="server"             ImageUrl="../images/Buttons/print.gif"             CommandName="Print"        >        </asp:ImageButton></ItemTemplate></asp:TemplateColumn>

aspx.cs

        private void MasterDG_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)        {            if (e.CommandName != "Print") return;            string sSignDate = e.Item.Cells[0].Text;            string sUnit = e.Item.Cells[1].Text;            string account = e.Item.Cells[2].Text;             Print( sSignDate, sUnit, account);        }

GirdView

注意事项
visible=fasle的话就不会bind,所以要先visible=true,bind完再设fasle

   GridView1.Columns[0].Visible = true;   GridView1.DataSource = source;   GridView1.DataBind();   //如果在一开始就设的话,就不会拿到值.所以要先拿完再设.   GridView1.Columns[0].Visible = false;            

<asp:ButtonField buttontype="Image" HeaderText="列印" ImageUrl="../images/Buttons/print.gif" CommandName="Print" ><ItemStyle CssClass="TACenter" Width="5%" /> </asp:ButtonField>

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e){   int index = Convert.ToInt32(e.CommandArgument);               GridView1.Rows[index].Cells[0].Text.ToString().Trim();}          

关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章