[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5197
  • Last Modified:

How can I force Gridview RowDataBound event to fire in update panel?

How can I force Gridview RowCreated event to fire in update panel? I have this code firng on other gridviews not in an update panle. I also tried using the RowCreated event, but I lose all of my style associated with the grid.

Any ideas on how to make this code work?
<asp:UpdatePanel ID="Upl1" runat="server">
                <ContentTemplate>
                    <asp:GridView ID="gvSearchResults" runat="server" DataKeyNames="iEmployeeID" HeaderStyle-ForeColor="White"
                        AllowSorting="true" OnSorting="gvSearchResults_Sorting" AllowPaging="true" PageSize="10"
                        OnPageIndexChanging="gvSearchResults_PageIndexChanging" Width="100%" AutoGenerateColumns="false"
                        CssClass="myGrid">
                        <EmptyDataTemplate>
                            No data to display.
                        </EmptyDataTemplate>
                        <HeaderStyle CssClass="myGridHeader"></HeaderStyle>
                        <AlternatingRowStyle CssClass="myGridAltItem" />
                        <RowStyle CssClass="myGridItem" />
                        <Columns>
                            <%--<asp:BoundField DataField="report_id" HeaderText="Report Id" ReadOnly="True" SortExpression="report_id" />--%>
                            <asp:BoundField DataField="vcCompletedFormFilling" HeaderText="Completed By" ReadOnly="True"
                                SortExpression="vcCompletedFormFilling" />
                            <asp:BoundField DataField="vcNameFormFilling" HeaderText="Submitted By" ReadOnly="True"
                                SortExpression="vcNameFormFilling" />
                            <asp:BoundField DataField="vcName" HeaderText="Emp Name" ReadOnly="True" SortExpression="vcName" />
                            <asp:BoundField DataField="vcSupervisor" HeaderText="Supervisor" ReadOnly="true"
                                SortExpression="vcSupervisor" />
                            <asp:BoundField DataField="Request_Type" HeaderText="Request Type" ReadOnly="true"
                                SortExpression="Request_Type" />
                            <asp:BoundField DataField="dtupdTime" HeaderText="Date Processed" DataFormatString="{0:g}"
                                ReadOnly="True" SortExpression="dtupdTime" HtmlEncode="false" />
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <input type="button" value="View Details " onclick="viewDetails('<%#Eval("iEmployeeID") %>','<%# Eval("Request_Type")%>')" />
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
                </ContentTemplate>
            </asp:UpdatePanel>

Open in new window



protected void gvSearchResults_RowDataBound(object sender, GridViewRowEventArgs e)
        {
           
            e.Row.Cells[4].Font.Bold = true;
            e.Row.Cells[4].Font.Size = FontUnit.Large;
            if (Convert.ToString(DataBinder.Eval(e.Row.DataItem, "Request_Type")) == "NEW")
            {
                e.Row.Cells[4].ForeColor = System.Drawing.Color.Green;
                //e.Row.ForeColor = System.Drawing.Color.Red;
            }
            if (Convert.ToString(DataBinder.Eval(e.Row.DataItem, "Request_Type")) == "EDIT")
            {
                e.Row.Cells[4].ForeColor = System.Drawing.Color.Blue;
                //e.Row.ForeColor = System.Drawing.Color.Red;
            }
            if (Convert.ToString(DataBinder.Eval(e.Row.DataItem, "Request_Type")) == "TERMINATE")
            {
                e.Row.Cells[4].ForeColor = System.Drawing.Color.Red;
                //e.Row.ForeColor = System.Drawing.Color.Red;
            }
            else
            {
                e.Row.ForeColor = System.Drawing.Color.Black;
            }
        }

Open in new window

0
devnewbee
Asked:
devnewbee
1 Solution
 
devnewbeeAuthor Commented:
The second link works, but I still lose my header style. :)
0
 
SAMIR BHOGAYTAFreelancer and IT ConsultantCommented:
<asp:UpdatePanel ID="updpSearch" runat="server">

<Triggers>

<asp:AsyncPostBackTrigger ControlID="btnSearch" />

</Triggers>

<ContentTemplate>

<!-- Panel pSecondStep -->

<asp:Panel ID="pSecondStep" runat="server" Visible="false" Width="100%">

<table cellpadding="2" cellspacing="0" border="2" class="backColor-XLight borderColor-Dark" style="width:100%">

<tr>

<td style="height: 60px">

<asp:Label runat="server" SkinID="SmallTitle" Text="<%$ Resources:Client_Directory, Results %>"> :</asp:Label><br />

<table cellpadding="2" cellspacing="0" border="0" runat="server" id="tSecondStepTables">

<tr>

<td><asp:Literal runat="server" Text="<%$ Resources:Client_Directory, ResultsExpl %>"></asp:Literal></td>

</tr>

<tr>

<td style="width:100%" valign="top">

 

<!-- Panel CssClass="flashThis" -->

<asp:Panel ID="pFlash" runat="server" CssClass="flashThis">

<asp:GridView runat="server" ID="gvCentral" SkinID="mainGrid" AutoGenerateColumns="False" Width="100%" OnRowDataBound="gvCentral_RowDataBound" AllowPaging="True" OnPageIndexChanging="gvCentral_PageIndexChanging" PageSize="15">

<Columns>

<asp:TemplateField HeaderText="&nbsp;">

<ItemTemplate>

<asp:HyperLink ID="HyperLink11" SkinID="MagnifyingGlassLittle" NavigateUrl='<%# String.Format("javascript:windowPop({0});", UrlIdentity(Eval("Id").ToString())) %>' runat="server"></asp:HyperLink>

</ItemTemplate>

</asp:TemplateField>

<asp:BoundField DataField="Title" HeaderText="<%$ Resources:Client_Profile, Title %>" />

<asp:TemplateField HeaderText="&nbsp;<%$ Resources:Client, Lname %>&nbsp;">

<ItemTemplate>

<asp:LinkButton ID="lbFoundMember" runat="server" CommandArgument='<%# Eval("Id").ToString() %>'

OnClick="teamAdd_Click" OnClientClick="return click_subscribe_button(this);"

Text='<%# Eval("LName") %>' ToolTip="<%$ Resources:Client_NewSubscription, addMemberToTeam %>" />

</ItemTemplate>

</asp:TemplateField>

<asp:BoundField HeaderText="<%$ Resources:Client, Fname %>" DataField="FName" />

<asp:BoundField DataField="MLName" HeaderText="<%$ Resources:Client, MLname %>" />

<asp:BoundField DataField="MFName" HeaderText="<%$ Resources:Client, MFname %>" />

<asp:BoundField DataField="Sex" HeaderText="<%$ Resources:Client, Sex %>" />

<asp:TemplateField HeaderText="&nbsp;">

</asp:TemplateField>
</Columns>

<PagerSettings Mode="NumericFirstLast" />

</asp:GridView>

<asp:PlaceHolder ID="phFruitlessSearch" runat="server">

<asp:Literal ID="Literal1" runat="server" Mode="Encode"

Text="<%$ Resources:Client_NewSubscription, noSearchResult %>"></asp:Literal>

</asp:PlaceHolder>

</asp:Panel>

<!-- Panel CssClass="flashThis" END -->

</td>

</tr>

</table>

</td>

</tr>

</table>

</asp:Panel>

<!-- Panel pSecondStep END -->

</ContentTemplate>

</asp:UpdatePanel>

 

====

     protected void loadSearchResult(Control parent)
    {
        MembersSubset s = new MembersSubset(Club.DirectorySubsetId);
        s.EnableSorting = true;
        s.EnableFiltering = true;
        string condition = this.getCondition(parent);
        bool emptySearch = String.IsNullOrEmpty(condition);
        if (emptySearch)
        {
            s.AdditionalFilter = "1 = 2";
        }
        else
        {
            s.AdditionalFilter = condition;
        }
        s.AdditionalPreSorting = "lname, fname, mlname, mfname";
        ArrayList fieldsToHave = new ArrayList(6);

        fieldsToHave.Add("lname");
        fieldsToHave.Add("fname");
        fieldsToHave.Add("mlname");
        fieldsToHave.Add("mfname");
        fieldsToHave.Add("sex");
        fieldsToHave.Add("title");

        // Check if all the fields are present
        if (s.Fields != null) foreach (QueryField qf in s.Fields)
        {
            fieldsToHave.Remove(qf.fieldName.ToLower());
        }

        foreach(string fieldToHave in fieldsToHave)
        {
            QueryField qf = new QueryField(fieldToHave, FieldType.charstring, "members");
            s.AddField(qf);
        }

        s.DataBind();

        GridView gvCentral = (GridView)(parent.FindControl("gvCentral"));
        Panel pSecondStep = (Panel)(parent.FindControl("pSecondStep"));
        PlaceHolder phFruitlessSearch = (PlaceHolder)(parent.FindControl("phFruitlessSearch"));
        gvCentral.DataSource = s.SubsetView;
        gvCentral.DataBind();

        pSecondStep.Visible = this.thisNewSearch;
        phFruitlessSearch.Visible = (gvCentral.Rows.Count == 0);
    }

    protected void gvCentral_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
           
            switch (e.Row.Cells[6].Text.ToLower())
            {
                case "true": e.Row.Cells[6].Text = Resources.Client_Directory.sexMale; break;
                case "false": e.Row.Cells[6].Text = Resources.Client_Directory.sexFemale; break;
            }
            //ScriptManager1.RegisterPostBackControl(e.Row.FindControl("lbFoundMember"));
        }
    }
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now