Click here to Skip to main content
15,074,483 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my databse table Employee like
UserID UserName UserExperience
101 Pandu 1-2
102 Nageswar 2-5

UserExperience Column
1--years
2--Months

i want update 101 record

i am click Edit button 101 employee details in edit mode and bind those data(one dropdown is bind one value and second dropdown is bind second value from UserExperience(1-2))



ASP.NET
<asp:TemplateField HeaderText="Experiance">
                          <ItemTemplate>
                              <asp:Label ID="lblExpyear" runat="server" Text='<%#Eval("Experiance")%>' />
                          </ItemTemplate>
                           <EditItemTemplate>
<%--                              <asp:TextBox ID="txtExp" runat="server" Text='<%#Eval("Experiance")%>' />--%>
                               <asp:DropDownList ID="ddlExpYear" runat="server">
                                    <asp:ListItem>- Select -</asp:ListItem>
                                    <asp:ListItem>0</asp:ListItem>
                                    <asp:ListItem>1</asp:ListItem>
                                    <asp:ListItem>2</asp:ListItem>
                                    <asp:ListItem>3</asp:ListItem>
                                    <asp:ListItem>4</asp:ListItem>
                                    <asp:ListItem>5</asp:ListItem>
                                    <asp:ListItem>6</asp:ListItem>
                                    <asp:ListItem>7</asp:ListItem>
                                    <asp:ListItem>8</asp:ListItem>
                                    <asp:ListItem>9</asp:ListItem>
                                    <asp:ListItem>10</asp:ListItem>
                               </asp:DropDownList>
                               <asp:DropDownList ID="ddlExpMonth" runat="server" >
                                    <asp:ListItem>- Select -</asp:ListItem>
                                    <asp:ListItem>0</asp:ListItem>
                                    <asp:ListItem>1</asp:ListItem>
                                    <asp:ListItem>2</asp:ListItem>
                                    <asp:ListItem>3</asp:ListItem>
                                    <asp:ListItem>4</asp:ListItem>
                                    <asp:ListItem>5</asp:ListItem>
                                    <asp:ListItem>6</asp:ListItem>
                                    <asp:ListItem>7</asp:ListItem>
                                    <asp:ListItem>8</asp:ListItem>
                                    <asp:ListItem>9</asp:ListItem>
                                    <asp:ListItem>10</asp:ListItem>
                               </asp:DropDownList>
                          </EditItemTemplate>
                      </asp:TemplateField>


What I have tried:

<asp:TemplateField HeaderText="Experiance">
<itemtemplate>
<asp:Label ID="lblExpyear" runat="server" Text='<%#Eval("Experiance")%>' />

<edititemtemplate>
<%-- <asp:TextBox ID="txtExp" runat="server" Text='<%#Eval("Experiance")%>' />--%>
<asp:DropDownList ID="ddlExpYear" runat="server">
<asp:ListItem>- Select -
<asp:ListItem>0
<asp:ListItem>1
<asp:ListItem>2
<asp:ListItem>3
<asp:ListItem>4
<asp:ListItem>5
<asp:ListItem>6
<asp:ListItem>7
<asp:ListItem>8
<asp:ListItem>9
<asp:ListItem>10

<asp:DropDownList ID="ddlExpMonth" runat="server" >
<asp:ListItem>- Select -
<asp:ListItem>0
<asp:ListItem>1
<asp:ListItem>2
<asp:ListItem>3
<asp:ListItem>4
<asp:ListItem>5
<asp:ListItem>6
<asp:ListItem>7
<asp:ListItem>8
<asp:ListItem>9
<asp:ListItem>10

Posted
Updated 25-May-16 2:24am
v2

1 solution

Try this,

Create a method in the code behind
C#
public string GetYearMonth(string value, string flag)
       {
           var items = value.Split('-');
           if (items.Length == 2)
           {
               if (flag =="y")
                   return items[0].Trim();
               else
                   return items[1].Trim();
           }
           return "- Select -";

       }


ASPX:

ASP.NET
<asp:DropDownList ID="ddlExpYear" SelectedValue='<%# GetYearMonth(Eval("Experiance").ToString(),"y")%>' runat="server">
.
.


ASP.NET
<asp:DropDownList ID="ddlExpMonth" SelectedValue='<%# GetYearMonth(Eval("Experiance").ToString(),"m")%>'     runat="server">
.
.
.
   
Comments
Member 11652153 25-May-16 8:48am
   
Thank you Karthik its working..
Karthik_Mahalingam 25-May-16 8:50am
   
welcome :)

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