如何在包含LinkBut​​ton的gridview中动态添加Template字段. [英] How to add Template field dynamically in gridview which contains LinkButton.

查看:72
本文介绍了如何在包含LinkBut​​ton的gridview中动态添加Template字段.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好专家,

我需要在运行时在GridView中添加包含LinkBut​​ton的模板字段.
还有链接按钮的OnClick我要执行一些操作.
有可能吗?

如果可以的话,请给我解决方案.

谢谢
Prashant

:thumbsup:

Hello Experts,

I am required to add Template Field which contains LinkButton in GridView at Run time.
And OnClick of link button I want to perform some operation.
Is it Possible??

and if it''s possible give me solution.

Thanking You,
Prashant

:thumbsup:

推荐答案

Private Sub ExportData()
        'Try
        objAttendance.Mode = "SelectEmpDetailsWithDeptAndDesignation"
        objAttendance.CmdType = "Select"
        objAttendance.CompanyID = Session("g_Company").ToString()
        objAttendance.EmpCode = IIf(ddlEmployee.SelectedItem.Text = "All", 0, ddlEmployee.SelectedItem.Value)
        objAttendance.DeptID = IIf(ddlDepartment.SelectedItem.Text = "All", 0, ddlDepartment.SelectedItem.Value)
        Dim ds As New DataSet
        ds = clsAttendance.SelectData(objAttendance)
        Dim sel_Month As Integer
        Dim sel_Year As Integer
        Dim sel_Date As Integer
        If IsDate(txtDate.Text) Then
            sel_Date = Convert.ToDateTime(txtDate.Text).Day
            sel_Month = Convert.ToDateTime(txtDate.Text).Month
            sel_Year = Convert.ToDateTime(txtDate.Text).Year
        Else
            sel_Month = Convert.ToInt32(ddlMonth.SelectedValue.Trim)
            sel_Year = Convert.ToInt32(ddlYear.SelectedValue.Trim)
        End If

        Dim dtReport As New DataTable
        dtReport.Columns.Add("Employee Code")
        dtReport.Columns.Add("Employee Name")
        dtReport.Columns.Add("Department")
        dtReport.Columns.Add("Designation")
        dtReport.Columns.Add("Date")
        dtReport.Columns.Add("Day")
        dtReport.Columns.Add("Lon-In Time")
        dtReport.Columns.Add("Log-Out Time")
        dtReport.Columns.Add("Total Hours")

        Dim ds_details As New DataSet
        Dim str_time As String = ""
        Dim dtCheckIn As DateTime = DateTime.Now
        Dim dtCheckOut As DateTime = DateTime.Now
        Dim j As Integer
        Dim i As Integer
        Dim k As Integer = 0
        For i = 0 To ds.Tables(0).Rows.Count - 1
            ds_details = clsAttendance.SelectUserTimeLog(ds.Tables(0).Rows(i).Item("V_Emp_Code"), sel_Month, sel_Year, sel_Date)
            For j = 0 To ds_details.Tables(0).Rows.Count - 1
                dtReport.Rows.Add()
                If j = 0 Then
                    dtReport.Rows(k)("Employee Code") = ds.Tables(0).Rows(i)("V_Emp_Code")
                    dtReport.Rows(k)("Employee Name") = ds.Tables(0).Rows(i)("V_Emp_Name")
                    dtReport.Rows(k)("Department") = ds.Tables(0).Rows(i)("V_Dept_Name")
                    dtReport.Rows(k)("Designation") = ds.Tables(0).Rows(i)("V_Designation_Name")
                End If
                dtReport.Rows(k)("Date") = Format


(Convert.ToDateTime(ds_details.Tables( 0 ).Rows(j)(" EmpAttDetDate"))), dd-MMM-yyyy"跨度>) dtReport.Rows(k)(" )=格式
(Convert.ToDateTime(ds_details.Tables(0).Rows(j)("EmpAttDetDate")), "dd-MMM-yyyy") dtReport.Rows(k)("Day") = Format


(Convert.ToDateTime(ds_details.Tables( 0 ).Rows(j)(" EmpAttDetDate"))), dddd") Dim time_checkin As 字符串 = " ' 'for CheckInTime 如果(ds_details.Tables( 0 ).Rows(j)( CheckInTime").ToString()<> " 0 ).Rows( j)(" ).ToString()<> & nbsp;") 0 ).Rows(j)(" ) time_checkin = time_checkin.Substring( 0 ,time_checkin.IndexOf(" :" + " + time_checkin) time_checkin = dtCheckIn.ToString(" ) 其他 time_checkin = " 结束 如果 Dim time_checkout As 字符串 = " ' 'for CheckOutTime 如果(ds_details.Tables( 0 ).Rows(j)( CheckOutTime").ToString()<> " 0 ).Rows( j)(" ).ToString()<> & nbsp;") 0 ).Rows(j)(" ) time_checkout = time_checkout.Substring( 0 ,time_checkout.IndexOf(" :" + " + time_checkout) time_checkout = dtCheckOut.ToString(" ) 其他 time_checkout = " 结束 如果 ' '总时长 如果(ds_details.Tables( 0 ).Rows(j)( 总小时").ToString()<> " 0 ).Rows( j)(" ).ToString()<> & nbsp;") 0 ).Rows(j)(" ) str_time =格式(str_time," ) 其他 str_time = " 结束 如果 dtReport.Rows(k)(" )= time_checkin dtReport.Rows(k)(" )= time_checkout dtReport.Rows(k)(" )= str_time k = k + 1 下一步 下一步 Dim GV As 新建 GridView GV.DataSource = dtReport GV.DataBind() Response.Clear() Response.Buffer = Response.AddHeader(" " 附件; filename = EmployeeAttendance.xls") Response.Charset = " Response.ContentType = " Dim sw As 新建 StringWriter() Dim 硬件 As 新建 HtmlTextWriter(sw) 对于 l As 整数 = 0 收件人 GV.Rows.Count- 1 ' 将文本样式应用于每行 GV.Rows(l).Attributes.Add(" 文本模式") 下一步 GV.RenderControl(硬件) Dim 样式 As 字符串 = " ' 'Response.Write(sw.ToString) Response.Output.Write(sw.ToString()) Response.Flush() 响应.结束() ' 异常捕获 ' showlabelmessage(对不起,发生某些服务器错误.请与您的管理员联系",lblError) ' RegisterBug(Request.Url.ToString,ex.Message,Err.Number,New System.Diagnostics.StackTrace(). GetFrame(0).GetMethod().Name,System.Net.Dns.GetHostAddresses(My.Computer.Name)(0).ToString,Session("g_User"),Me.Title) ' 结束尝试 结束
(Convert.ToDateTime(ds_details.Tables(0).Rows(j)("EmpAttDetDate")), "dddd") Dim time_checkin As String = "" ''for CheckInTime If (ds_details.Tables(0).Rows(j)("CheckInTime").ToString() <> "" And ds_details.Tables(0).Rows(j)("CheckInTime").ToString() <> "&nbsp;") Then time_checkin = ds_details.Tables(0).Rows(j)("CheckInTime") time_checkin = time_checkin.Substring(0, time_checkin.IndexOf(":") + 3) dtCheckIn = Convert.ToDateTime("01-01-2008 " + time_checkin) time_checkin = dtCheckIn.ToString("hh:mm tt") Else time_checkin = "" End If Dim time_checkout As String = "" ''for CheckOutTime If (ds_details.Tables(0).Rows(j)("CheckOutTime").ToString() <> "" And ds_details.Tables(0).Rows(j)("CheckOutTime").ToString() <> "&nbsp;") Then time_checkout = ds_details.Tables(0).Rows(j)("CheckOutTime") time_checkout = time_checkout.Substring(0, time_checkout.IndexOf(":") + 3) dtCheckOut = Convert.ToDateTime("01-01-2008 " + time_checkout) time_checkout = dtCheckOut.ToString("hh:mm tt") Else time_checkout = "" End If ''for Total Hours If (ds_details.Tables(0).Rows(j)("TotalHour").ToString() <> "" And ds_details.Tables(0).Rows(j)("TotalHour").ToString() <> "&nbsp;") Then str_time = ds_details.Tables(0).Rows(j)("TotalHour") str_time = Format(str_time, "Short Time") Else str_time = "" End If dtReport.Rows(k)("Lon-In Time") = time_checkin dtReport.Rows(k)("Log-Out Time") = time_checkout dtReport.Rows(k)("Total Hours") = str_time k = k + 1 Next Next Dim GV As New GridView GV.DataSource = dtReport GV.DataBind() Response.Clear() Response.Buffer = True Response.AddHeader("content-disposition", "attachment;filename=EmployeeAttendance.xls") Response.Charset = "" Response.ContentType = "application/vnd.ms-excel" Dim sw As New StringWriter() Dim hw As New HtmlTextWriter(sw) For l As Integer = 0 To GV.Rows.Count - 1 'Apply text style to each Row GV.Rows(l).Attributes.Add("class", "textmode") Next GV.RenderControl(hw) Dim style As String = "<style> .textmode { mso-number-format:\@; } </style>" ''Response.Write(sw.ToString) Response.Output.Write(sw.ToString()) Response.Flush() Response.End() 'Catch ex As Exception ' showlabelmessage("Sorry Some Server Error has occured..Please Contact Your Administrator", lblError) ' RegisterBug(Request.Url.ToString, ex.Message, Err.Number, New System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, System.Net.Dns.GetHostAddresses(My.Computer.Name)(0).ToString, Session("g_User"), Me.Title) 'End Try End Sub


这篇关于如何在包含LinkBut​​ton的gridview中动态添加Template字段.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆