How to used selected value of DropDownList in Grid View

Posted by Naeem2049 under Regular Expressions on 4/25/2011 | Points: 10 | Views : 12654 | Status : [Member] | Replies : 3
Hi,

I have a GridView that has a DropDownList in one of the columns.

When I edit and update any row I would like to grab the Selected Value of that DropDownList when I'm in the GridView_RowUpdating event.

Any ideas?

Thanks

NAEEM




Responses

Posted by: Ndebata on: 4/25/2011 [Member] Starter | Points: 25

Up
0
Down
void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
DropDownList cmb = GridView1.Rows[e.RowIndex].FindControl("<DropDownList ID>") as DropDownList;
if(cmb!=null)
{
//cmb.SelectedValue
}
}

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

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

Up
0
Down

In .aspx Page
-----------------------------------
<asp:TemplateField HeaderText="Status" SortExpression="Status">
<ItemTemplate>
<asp:Label ID="lblStatus" runat="server" Text='<%# Eval("Status")%>' />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlstatus" CssClass="changedropdown" runat="server">
</asp:DropDownList>
<img src="../../Themes/Images/reg-alert-icon.png" class="alert" id="imgeditstatus" style="margin-left: 5px;
float: right" alt="manditory" />
<asp:Label ID="lblNewStatus" runat="server" Text='<%# Eval("Status")%>' Visible="false" />
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlFooterStatus" CssClass="changedropdown" runat="server" Width="120">
</asp:DropDownList>
<img src="../../Themes/Images/reg-alert-icon.png" class="alert" id="imgstatus" style="margin-left: 5px;
float: right" alt="manditory" />
</FooterTemplate>
</asp:TemplateField>
in .aspx.cs
-------------------------------

in RowDataBound:
----------------------
if (e.Row.RowType == DataControlRowType.DataRow)
{

DropDownList ddlStatus = (DropDownList)e.Row.FindControl("ddlStatus");
if (ddlType != null && ddlStatus != null)
{
ResponseDTO objResponseDTO3 = (ResponseDTO)new TP.Services().Execute(TVCConstants.GetstatusDetails);
ddlStatus.DataSource = objResponseDTO3.ReturnObject;
ddlStatus.DataTextField = "status";
ddlStatus.DataValueField = "status";
ddlStatus.DataBind();
ddlStatus.SelectedItem.Text = lblNewStatus.Text;

}
}

Row Updating
----------------------------
GridViewRow row = (GridViewRow)grdCitationConfg.Rows[e.RowIndex];
DropDownList ddlstatus = (DropDownList)grdCitationConfg.Rows[e.RowIndex].Cells[1].Controls[1];
if (ddlstatus.SelectedValue.ToString() != "0")
{
obj.Status = ddlstatus.SelectedItem.Text;
}

thanks srinivas.

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

Posted by: Robert on: 10/6/2011 [Member] Starter | Points: 25

Up
0
Down
This is good tutorial on DropDownList in DetailsView: http://it-tutorial.net/tutorial-asp-net-creating-dropdownlist-in-detailsview.html

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

Login to post response