Click here to Skip to main content
15,920,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a GridView for TAX master i have table with name tax_master inside tax_master i have a column tax_status and its data type is bit
Now i want to bind database value with my dropdown list autogenrate edit button is true

Here is my code for GridView

XML
<asp:TemplateField HeaderText="Active">
                        <EditItemTemplate>
                            <asp:DropDownList ID="tax_status" runat="server">
                                <asp:ListItem Value="1">Yes</asp:ListItem>
                                <asp:ListItem Value="0">No</asp:ListItem>
                            </asp:DropDownList>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="lbl_tax_status" runat="server"><%# (Boolean.Parse(Eval("tax_status").ToString())) ? "Yes" : "No" %></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>


When i clicked on Edit Then If tax status is 0 i.e. false then i want to show the No default selected in my drop down list and if i changed it to 1 i.e. True then changes must be saved to database and vice-versa

Please help me to solve my puzzle thanks in advance
Posted
Comments
prasanna.raj 10-Sep-14 7:42am    
Y u didn't try in cs part... try this...

<asp:ListItem Value=" ">-select-
<asp:ListItem Value="0">Yes
<asp:ListItem Value="1">Yes

1 solution

Assuming the data type of your tax_status column is bit, try:
ASP.NET
<EditItemTemplate>
    <asp:DropDownList ID="tax_status" runat="server" SelectedValue='<%# Bind("tax_status") %>'>
        <asp:ListItem Value="True">Yes</asp:ListItem>
        <asp:ListItem Value="False">No</asp:ListItem>
    </asp:DropDownList>
</EditItemTemplate>
 
Share this answer
 
Comments
Omkar Hendre 10-Sep-14 8:38am    
Great its working perfectly fine for me big thanks to you dear thanks a lot

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