Dim index As Integer = CType(CType(sender, LinkButton).Parent.Parent, GridViewRow).RowIndex
Dim lb_gp_no As LinkButton = CType(GridView1.Rows(index).FindControl("LBT0_GP_NO"), LinkButton)
在UpdatePanel下觸發 GridView中的控制項 (參考網站)
頁面使用UpdatePanel狀態下,會加入以下Code 使之可以PostBack
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="But_addFileUp" />
</Triggers>
</asp:UpdatePanel>
若要按下的控制項是在GridView中,則無法寫在<Triggers>中
解決方法:
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Me.RegisterPostBackControl()
End Sub
Private Sub RegisterPostBackControl()
For Each row As GridViewRow In GridView1.Rows
Dim lnkFull As LinkButton = TryCast(row.FindControl("lnkFull"), LinkButton)
ScriptManager.GetCurrent(Me).RegisterPostBackControl(lnkFull)
Next
End Sub
GridView BoundField、TemplateField 千分位
在BoundField之下 DataFormatString="{0:N0}"
在TemplateField之下
'<%# string.Format("{0:N0}",Eval("Qty")) %>'
或
'<%# Eval("Qty","{0:N0}") %>'
以上設定僅千分位,不會有小數點之設定
GridView在footer加上總計欄位 參考網站
Protected Sub GridView1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.PreRender
Dim footer As GridViewRow = New GridViewRow(-1, -1, DataControlRowType.Footer, DataControlRowState.Normal)
Dim dtc0 As TableCell = New TableCell()
Dim dtc1 As TableCell = New TableCell()
Dim dt As DataTable = New DataTable()
Dim dv As DataView = New DataView()
Dim iCount As Integer = 0
Dim iPercent As Integer = 0
dv = CType(SqlDataSource1.Select(DataSourceSelectArguments.Empty), DataView) 'Get DataView
dt = dv.ToTable()
iCount = Convert.ToInt32(dt.Compute("sum(subtotal)", ""))
iPercent = Convert.ToInt32(dt.Compute("sum(subtotal)", ""))
dtc0.Text = "總計"
dtc1.Text = iCount.ToString()
footer.Controls.Add(dtc0)
footer.Controls.Add(dtc1)
GridView1.Controls(0).Controls.AddAt(GridView1.Controls(0).Controls.Count - 1, footer)
End Sub
GridView BoundField、TemplateField 千分位
在BoundField之下 DataFormatString="{0:N0}"
在TemplateField之下
'<%# string.Format("{0:N0}",Eval("Qty")) %>'
或
'<%# Eval("Qty","{0:N0}") %>'
以上設定僅千分位,不會有小數點之設定
GridView在footer加上總計欄位 參考網站
Protected Sub GridView1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.PreRender
Dim footer As GridViewRow = New GridViewRow(-1, -1, DataControlRowType.Footer, DataControlRowState.Normal)
Dim dtc0 As TableCell = New TableCell()
Dim dtc1 As TableCell = New TableCell()
Dim dt As DataTable = New DataTable()
Dim dv As DataView = New DataView()
Dim iCount As Integer = 0
Dim iPercent As Integer = 0
dv = CType(SqlDataSource1.Select(DataSourceSelectArguments.Empty), DataView) 'Get DataView
dt = dv.ToTable()
iCount = Convert.ToInt32(dt.Compute("sum(subtotal)", ""))
iPercent = Convert.ToInt32(dt.Compute("sum(subtotal)", ""))
dtc0.Text = "總計"
dtc1.Text = iCount.ToString()
footer.Controls.Add(dtc0)
footer.Controls.Add(dtc1)
GridView1.Controls(0).Controls.AddAt(GridView1.Controls(0).Controls.Count - 1, footer)
End Sub
沒有留言:
張貼留言