Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Experts,

I have a Gridview with bound fields as below.
XML
<asp:GridView ID="gdvAll" runat="server" AllowPaging="true" PageSize="10" AllowSorting="true" OnRowDataBound="gdvAll_RowDataBound"
                                Style="vertical-align: middle;" HorizontalAlign="Center" OnPageIndexChanging ="ongdvPageIndex_Clicked"
                                AutoGenerateColumns="false" OnSelectedIndexChanged="OnSelectedIndexChanged" EnableSortingAndPagingCallbacks="false"
                                CssClass="Grid" AlternatingRowStyle-CssClass="alt" PagerStyle-CssClass="pgr">
                                <Columns>
                                    <asp:TemplateField HeaderText="SNo">
                                        <ItemTemplate>
                                            <%# Container.DataItemIndex + 1 %>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:BoundField DataField="TITRANO" HeaderText="MFI Tracking no" />
                                    <asp:BoundField DataField="TIDEANO" HeaderText="Dealer Account#" />
                                    <asp:BoundField DataField="TINPCLM" HeaderText="Dealer Contact" />
                                    <asp:BoundField DataField="TISTATS" HeaderText="Status" />
                                    <asp:BoundField DataField="TIBATNO" HeaderText="Batch no" />
                                    <asp:BoundField DataField="TIRACKNO" HeaderText="Rack no" />
                                    <asp:BoundField DataField="TICLMNO" HeaderText="Claim Date" />
                                    <asp:ButtonField Text="Details" HeaderText="Details" CommandName="Select" />
                                    <asp:TemplateField HeaderText="File">
                                         <ItemTemplate>
                                            <asp:LinkButton ID="btndownload" runat="server" Text="Download" CommandArgument='<%# Eval("TILOCA") %>'
                                             CommandName="Download" OnClick="btnDownload_Click" CausesValidation="false" />
                                         </ItemTemplate>
                                     </asp:TemplateField>
                                     <asp:TemplateField HeaderText="Error Info">
                                     <ItemTemplate>
                                    
                                     </ItemTemplate>
                                     </asp:TemplateField>

                                </Columns>
                            </asp:GridView>



Now before binding the fields to Grid, I want to check a column value from the Datatable, if it is Col16="Yes" then bind "Error Info" column with a Text "File required"
Here is my bind code
VB
Private Sub BindGrid()
       If (txtClaim.Text.Length > 0) Then
           'Dim ds As DataSet = dbnet.GetClaims(txtClaim.Text.ToString())
           Dim arr() As String = txtClaim.Text.ToString().Split("-")
           Dim condi As String = arr(2)
           Dim ds As DataSet = dbnet.GetData1("DEVSUSH.CLTRAINF", "TITID", condi.ToString().Trim())
           gdvAll.DataSource = ds.Tables(0)
           gdvAll.DataBind()
       Else
           'Dim dsAll As DataSet = dbnet.GetAllClaims()
           Dim dsAll As DataSet = dbnet.GetData1("DEVSUSH.CLTRAINF", "", "")
           gdvAll.DataSource = dsAll.Tables(0)
           gdvAll.DataBind()
           ViewState("gdvAll") = dsAll.Tables(0)
       End If
   End Sub


VB
Protected Sub gdvAll_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
        Try
            Dim index As Integer = 0
            If (e.Row.RowType = DataControlRowType.DataRow) Then
                Dim ColValue As String = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "TILOCA"))
                Dim lnk As LinkButton = DirectCast(e.Row.FindControl("btndownload"), LinkButton)
                If Not ColValue Is String.Empty Then
                    ' if Already file is attached show
                    e.Row.FindControl("btndownload").Visible = True
                Else
                    e.Row.FindControl("btndownload").Visible = False

                End If

            End If
        Catch ex As Exception
            LogError.LogErrorIntoTextFile(ex, "gdvAll_RowDataBound()")
        End Try
    End Sub


Is this possible? If yes can you tell me how can I do that?
Posted

1 solution

Something like this should do the trick:
ASP.NET
<asp:TemplateField HeaderText="Error Info">
<ItemTemplate>
    <asp:Label runat="server"
        Visible='<% String.Equals(Eval("Col16", "{0}"), "Yes", StringComparison.OrdinalIgnoreCase) %>'
        Text="File required"
    />
</ItemTemplate>
</asp:TemplateField>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900