GridView_Rowdatabound不触发 [英] GridView_Rowdatabound not firing

查看:81
本文介绍了GridView_Rowdatabound不触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



GridView_Rowdatabound无法触发,当我在Sql数据源中使用select参数以及在gridview中未绑定的数据时,

aspx页面

Hi,

GridView_Rowdatabound not firing and when i use select parameter in Sql datasource and also data not bound in the gridview

aspx Page

<asp:GridView ID="GridView1" runat="server" align="center" AllowPaging="True" DataKeyNames="ProjectCode"
                                 AutoGenerateColumns="False" class="tabulardata" DataSourceID="SqlDataSource1" 
                                 HorizontalAlign="Center" Width="100%">
                                 <columns>
                                      <asp:TemplateField HeaderText="Sl.No" ItemStyle-HorizontalAlign="Center" 
                                         ItemStyle-Width="2%">
                                         <itemtemplate>
                                             <asp:Label ID="Sno" runat="server">
                                         </itemtemplate>
                                         <itemstyle horizontalalign="Center" />
                                     
                                     <asp:BoundField HeaderText="Project Code" Visible="true" DataField="ProjectCode"
                                         ItemStyle-HorizontalAlign="center" SortExpression="ProjectCode">
                                     
                                      <asp:BoundField HeaderText="AsstProjLead" DataField="AsstProjLead"
                                         ItemStyle-HorizontalAlign="center" ReadOnly="true" 
                                         SortExpression="AsstProjLead">
                                     
                                 </columns>
                                 <alternatingrowstyle backcolor="#FFF5F5" />   
                     
                 <asp:SqlDataSource ID="SqlDataSource1" runat="server"   
                    ConnectionString="<%$ConnectionStrings:MPP%>"
                   SelectCommand="Select ProjectCode,emp_name+'' ''+ emp_initial+'' - ''+emp_number as AsstProjLead
                                  from csAsstProjLeads A inner join 
                                  idpeapp.dbo.view_employee V on V.emp_number=A.AsstProjLead and A.Projectcode=@ProjectCode">  
                  <SelectParameters>
                    <asp:Parameter Name="ProjectCode" Type="String"/>
                  </SelectParameters>


aspx.vb代码


aspx.vb Code

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        Dim sno As New Label
        Dim SrNo As Integer
        If e.Row.RowType = DataControlRowType.DataRow Then
            SrNo = (GridView1.PageIndex + 1) * 10 - 9
            sno = e.Row.FindControl("Sno")
            sno.Text = e.Row.RowIndex + SrNo
            sno.DataBind()
        End If
        If e.Row.RowType = DataControlRowType.DataRow Then
           DataBinder.Eval(e.Row.DataItem, "ProjectNoID")
        End If
End Sub


请帮助解决此问题.

问候,
Ganesh.S


Pls. help to solve this problem.

Regards,
Ganesh.S

推荐答案

ConnectionStrings:MPP%> SelectCommand =选择ProjectCode,emp_name +''''+ emp_initial +''-''+ emp_number作为AsstProjLead 来自csAsstProjLeads内部联接 V.emp_number = A.AsstProjLead和A.Projectcode=@ProjectCode>上的idpeapp.dbo.view_employee V < SelectParameters> < asp:参数名称="ProjectCode"类型="String"/> </SelectParameters>
ConnectionStrings:MPP%>" SelectCommand="Select ProjectCode,emp_name+'' ''+ emp_initial+'' - ''+emp_number as AsstProjLead from csAsstProjLeads A inner join idpeapp.dbo.view_employee V on V.emp_number=A.AsstProjLead and A.Projectcode=@ProjectCode"> <SelectParameters> <asp:Parameter Name="ProjectCode" Type="String"/> </SelectParameters>


aspx.vb代码


aspx.vb Code

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        Dim sno As New Label
        Dim SrNo As Integer
        If e.Row.RowType = DataControlRowType.DataRow Then
            SrNo = (GridView1.PageIndex + 1) * 10 - 9
            sno = e.Row.FindControl("Sno")
            sno.Text = e.Row.RowIndex + SrNo
            sno.DataBind()
        End If
        If e.Row.RowType = DataControlRowType.DataRow Then
           DataBinder.Eval(e.Row.DataItem, "ProjectNoID")
        End If
End Sub


请帮助解决此问题.

问候,
Ganesh.S


Pls. help to solve this problem.

Regards,
Ganesh.S


您好,

在xml中注册onrowdatabound方法
OnRowDataBound ="GridView1_RowDataBound"

谢谢
Sanjeev
Hello,

in xml register onrowdatabound method
OnRowDataBound="GridView1_RowDataBound"

thanks
Sanjeev


这篇关于GridView_Rowdatabound不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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