dropdown in gridview

Posted by Sepede123 under ASP.NET on 9/4/2011 | Points: 10 | Views : 1496 | Status : [Member] | Replies : 3
hi
i have a dropdown list in gridview at editItemtemplate and i want connect it to database ,
means when i click on edit button on gridview the dropdown list fill with data of datasource,so which event and which coe i use to connect it to datasource without useing of sqldatasource object!
i write the follow code but it give error ?
con.Open();
DropDownList drop = new DropDownList();
drop = (DropDownList)GridView2.Rows[k].Cells[4].FindControl("DropDownList2");
string str = "select distinct(kind_book)from book";
DataSet set = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(str, con);
drop.DataTextField = "kind_book";
drop.DataValueField = "kind_book";
drop.DataSource = set;
drop.DataBind();
con.Close()
please send resolve to my email:sepede123@yahoo.com




Responses

Posted by: SheoNarayan on: 9/5/2011 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Hi Sepe..

Read this article http://www.dotnetfunda.com/articles/article989-dropdownlist-in-the-gridview-keeping-aspnet-forms-control-in-gridview-.aspx to get solution of your problem.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Sepede123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Srinivas673 on: 9/5/2011 [Member] Starter | Points: 25

Up
0
Down
<EditItemTemplate>
<asp:DropDownList ID="ddlstatus" CssClass="changedropdown" runat="server">
</asp:DropDownList>
<asp:Label ID="lblNewStatus" runat="server" Text='<%# Eval("Status")%>' />
</EditItemTemplate>

in RowDataBound
------------------------
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblNewStatus = (Label)e.Row.FindControl("lblNewStatus");
DropDownList ddlStatus = (DropDownList)e.Row.FindControl("ddlStatus");
ddlStatus.DataSource = objResponseDTO3.ReturnObject;
ddlStatus.DataTextField = "status";
ddlStatus.DataValueField = "status";
ddlStatus.DataBind();
ddlStatus.SelectedItem.Text = lblNewStatus.Text;
}
row updating
-----------------------
DropDownList ddlstatus = (DropDownList)grdCitationConfg.Rows[e.RowIndex].Cells[1].Controls[1];
obj.Status = ddlstatus.SelectedItem.Text;

Sepede123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Taanu51 on: 9/6/2011 [Member] Starter | Points: 25

Up
0
Down
its better to use xml datasource to fill the datasorce..simple way to bind xml datsource example

http://www.developerscode.com/2011/05/add-xml-datasource-to-gridview-dropdown.html

Tanisha Sayyad
.Net and Android Developer
INDIA(Andhra Pradesh)

Sepede123, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response