Note that there are some explanatory texts on larger screens.

plurals
  1. POissue with populating dropdownlist in gridview edit mode in c#
    primarykey
    data
    text
    <p>I am having <code>editable Gridview</code> with column named <code>Country</code> which has so long listing.</p> <p>When I am showing data the value of <code>Country</code> is in <code>Label</code> but when I choose edit should show <code>DropDownList</code> with country listings. I am able to show listings. <code>it should show the country selected as that was in label</code>.</p> <p>I have tried with this but dropdownlist is filled with <code>System.Row.DataRowView</code> also it is not set at SelectedValue given as <code>cvalue</code></p> <p>aspx page</p> <pre><code>&lt;asp:TemplateField HeaderText="Country"&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID="lblCountry" runat="server" Text='&lt;%#Bind("Country")%&gt;'&gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;EditItemTemplate&gt; &lt;asp:DropDownList ID="ddlCCountry" runat="server" Height="21px" Style="margin-left: 0px" Width="194px"&gt; &lt;asp:ListItem Value="-1"&gt;Select..&lt;/asp:ListItem&gt; &lt;asp:ListItem Value="af"&gt;Afghanistan&lt;/asp:ListItem&gt; &lt;asp:ListItem Value="ax"&gt;Aland Islands&lt;/asp:ListItem&gt; &lt;asp:ListItem Value="al"&gt;Albania&lt;/asp:ListItem&gt; &lt;/asp:DropDownList&gt; &lt;EditItemTemplate&gt; </code></pre> <p>.cs file</p> <pre><code> void gvhoteldetail_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowState == DataControlRowState.Edit) { string cnm="",cvalue=""; string getCountry = "Select * from tbl_countrynames where `Name`='" + cname + "'"; string getCountrynames = "Select * from tbl_countrynames"; MySqlConnection con = new MySqlConnection(connection); MySqlCommand cmd1 = new MySqlCommand(getCountrynames, con); DataSet ds1 = new DataSet(); MySqlDataAdapter da1 = new MySqlDataAdapter(cmd1); da1.Fill(ds1); MySqlCommand cmd = new MySqlCommand(getCountry, con); DataSet ds = new DataSet(); MySqlDataAdapter da = new MySqlDataAdapter(cmd); da.Fill(ds); if (ds.Tables[0].Rows.Count &gt; 0) { cnm = ds.Tables[0].Rows[0]["Name"].ToString(); cvalue = ds.Tables[0].Rows[0]["Value"].ToString(); } DropDownList ddlcountry = (DropDownList)e.Row.FindControl("ddlCCountry"); ddlcountry.DataSource = ds1; ddlcountry.SelectedValue = cvalue; ddlcountry.DataBind(); } </code></pre> <p>What could be wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload