GridView_Rowdatabound

Posted by Ganthi1977 under ASP.NET on 6/28/2011 | Points: 10 | Views : 1330 | Status : [Member] | Replies : 2
Hi,

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

aspx Page

Collapse | Copy Code
<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 Code

Collapse | Copy 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 SubPls. help to solve this problem.

Regards,
Ganesh.S




Responses

Posted by: Swapnil on: 6/28/2011 [Member] Starter | Points: 25

Up
0
Down
Hi Ganesh,

Where are you passing ProjectCode which is parameter of SqlDataSource1 control? You have to pass / map parameter (either control or querystring parameter or depend on where it is come from) to execute the query and bind the grid.

Thanks,
Swapnil.

Thanks and Regards,
Swapnil

Ganthi1977, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vforvijay on: 6/28/2011 [Member] Starter | Points: 25

Up
0
Down
hi...
To fire a rowdatabound you have to use Databound field instead of item template...also you have to mention data field to fire..
Refer it...http://vbdotnetaddict.blogspot.com/2011/06/rowdatabound-event-in-gridview-using.html

Ganthi1977, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response