2014年7月13日 星期日

[RESOLVED] Unable to find dropdownlist in grid view edit item template.


Hi all, I need your appreciated help.


Why this dropdownlist in grid view edit item template is empty when edit the gridview?


Can you help me?


.aspx


                AutoGenerateColumns="False" PageSize="10" ShowHeader="true"
OnRowDataBound="GridView1_RowDataBound">



<%#Eval("Email")%>











.cs


.cs

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow && DecoderView.EditIndex == e.Row.RowIndex)
{
DropDownList txtNewEmail = (DropDownList)e.Row.FindControl("txtNewEmail");

string query = "SELECT ";
query = query + " EMail, ";
query = query + "FROM ";
query = query + " `tbl; ";

OdbcCommand objCmd = new OdbcCommand(query, myConnectionString);
objCmd.CommandType = CommandType.Text;
objCmd.CommandText = query;
objCmd.Connection = myConnectionString;
myConnectionString.Open();
txtNewEmail.DataSource = objCmd.ExecuteReader();
txtNewEmail.DataTextField = "EMail";
txtNewEmail.DataValueField = "EMail";
txtNewEmail.DataBind();
}
}









MiguelRVR



string query = "SELECT ";
query = query + " EMail, ";
query = query + "FROM ";
query = query + " `tbl; ";


Are you sure your query is correct and returning data? It looks me to have an extra comma.. change it


string query = "SELECT EMail FROM tbl";

Regards.






thank you, but the ddl is more empty ... I've corrected sql query



Your DropDownList is in footer, not in EditItemTemplate.



oned_gk


Your DropDownList is in footer, not in EditItemTemplate.


Ok, I've tried this but the ddl is more empty .... 



DataTextField="Email" DataValueField="Email" SelectedValue='<%# Bind("Email") %>'>





ProviderName="<%$ ConnectionStrings:ConnMySQL.ProviderName %>" SelectCommand="SELECT
EMail
FROM
`tbl`
WHERE
Unity LIKE CONCAT('%',?,'%'); ">






SelectCommand="SELECT EMail FROM tbl WHERE Unity LIKE '%' + @EmailID +'%'"...i think you need to move it to EditItemTemplate. It should work without code behind.

沒有留言:

張貼留言