Thursday, January 3, 2013

Data binding in gridview using the ternary operator

Data binding in gridview using the ternary operator


<asp:GridView ID="GridView_ViewQuestionPaper" runat="server" CssClass="dataGridId"
BorderStyle="None" DataKeyNames="Qid" AutoGenerateColumns="False" ShowFooter="True"
GridLines="Vertical" CellPadding="4" BorderWidth="1px" AllowSorting="True" AllowPaging="True"
PageSize="10" OnRowCommand="GridView_ViewQuestionPaper_RowCommand" OnPageIndexChanging="GridView_ViewQuestionPaper_PageIndexChanging">
<Columns>
    <asp:TemplateField HeaderText="Delete">
        <ItemStyle Wrap="False" BorderWidth="1px" VerticalAlign="Top"></ItemStyle>
        <ItemTemplate>
            <asp:ImageButton ID="1ImgBtnDelete" runat="server"  ToolTip='<%# Eval("IsApproved").ToString().Equals("Yes".ToString()) ? Convert.ToString("Not allowed") :Convert.ToString("Delete question") %>'
            CommandName="Deleterecord" CommandArgument='<%#Eval("Qid") %>' Enabled='<%# Eval("IsApproved").ToString().Equals("Yes".ToString()) ? Convert.ToBoolean(0) : Convert.ToBoolean(1) %>' ImageUrl="../../Resources/Images/DataGrid/icon-delete.gif">
        </asp:ImageButton>
        </ItemTemplate>
    </asp:TemplateField>
</Columns>
</asp:GridView>

1 comment: