Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Expert,

I am using asp.net c sharp.

In my edit_event page i am editing event information using listview.

In my edittemplate textbox vind perfectly.
eg.

<td>Event Name:</td>
                <td>
                    <asp:TextBox ID="txtEditEventName" runat="server" 
                        Text='<%# Bind("event_name") %>' />
                </td>



above code working fine.

now i want dropdownlist for editing in edittemplate to edit country.
I wrote following code.

<td>Country :</td>
                <td>
                     
                    <asp:DropDownList ID="lstEditCountry" runat="server" 
                              
                            DataTextField="country_name"
                            DataValueField="country_id"
                               SelectedValue='<%# Bind("country_id") %>'
                              />


it shows only blank dropdown.
How to show all countries in this dropdownlist.

is there any event i have to use for this purpose? and how ?

Thanks in advance.......
Posted

1 solution

try this one

C#
 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
 if (e.CommandName == "Edit")
        {
            DropDownList drplist= (DropDownList)GridView1.FooterRow.FindControl("dropdownlist1");

//
//Fill the dataset in ds here
//

drplist.DataSource = ds;
   drplist.DataBind();

}
}
 
Share this answer
 
v2
Comments
udusat13 25-Oct-11 5:35am    
Thanks for code..
But i am n using listview not gridview.

So which event is necessary?
Please help me?
shek124 25-Oct-11 6:26am    
For Listview, use ItemDatabound Event.

udusat13 25-Oct-11 7:12am    
I write following code on ItemBoundEvent.

but it throw exception object null reference.datatable working fine.
but when i control reach at point
listEditCountry.DataSource = dt; it throws exception.



ListViewDataItem item = (ListViewDataItem)e.Item;

DropDownList listEditCountry = (DropDownList)e.Item.FindControl("lstEditCountry");


try
{
string queryStrUserType = "SELECT country_id,country_name FROM crm_countries";

ClassDtBaseConnect clsDtResult = new ClassDtBaseConnect();
DataTable dt = clsDtResult.GetDataTable(queryStrUserType);



listEditCountry.DataSource = dt; //this line throw exception object null reference. datatable dt working fine.
listEditCountry.DataValueField = "country_id";
listEditCountry.DataTextField = "country_name";




listEditCountry.DataBind();
udusat13 28-Oct-11 8:31am    
I used condition
if (listvwEventResult.EditIndex > -1)


Now its working.

Thanks..............

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