iT邦幫忙

0

DataGrid & GridView 按鈕功能

  • 分享至 

  • xImage
  •  

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();
}
          

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言