从gridview内的下拉列表中查找选定的文本时出现问题 [英] Problem finding Selected Text from a drop-down list inside a gridview

查看:70
本文介绍了从gridview内的下拉列表中查找选定的文本时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好...

我在网格视图的编辑项目模板中使用Dorp-down列表,而更新它不是在检索下拉列表的选定项目,而是在检索下拉列表的第一个列表项目.

以下是.aspx页的代码:-

Hi All...

I am using Dorp-down list in edit item template of grid-view, while updating it is not retreiving the selected-item of the drop-down list instead its retreiving the first list item of drop-down list.

following is the code for .aspx page:-

<asp:TemplateField HeaderText="Status">
                           <EditItemTemplate>
                            <center>   <asp:DropDownList ID="ddlStatus" runat="server">

                                   <asp:ListItem>Dispached</asp:ListItem>
                                   <asp:ListItem>Delivered</asp:ListItem>
                                   <asp:ListItem >Pending</asp:ListItem>
                               </asp:DropDownList></center>
                           </EditItemTemplate>
                           <ItemTemplate>
                                <asp:Label ID="Label6" runat="server" Text='<%# Eval("OStatus") %>'  ForeColor="Red"></asp:Label>
                                </ItemTemplate>
                       </asp:TemplateField>




以下是gridview_rowupdating的aspx.cs代码:-




following is the code of aspx.cs for gridview_rowupdating:-

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
   {
       string id = GridView1.DataKeys[e.RowIndex].Values[0].ToString();
       DropDownList ddlstatus = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlStatus");
       string sd = ddlstatus.Text;
       SqlCommand cmdUpdate = new SqlCommand("Update Orders set OStatus = ''" + status.SelectedItem.Text + "'' where OID=''" + id + "''", con);
       cmdUpdate.ExecuteNonQuery();
       con.Close();
       GridView1.EditIndex = -1;
       databind();
   }

推荐答案

替换
ddlstatus.Text


ddlstatus.SelectedValue

ddlstatus.SelectedItem.ToString()


ddlstatus.selecteditem.text
or
ddlstatus.selectedtext


尝试一下
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
 {
  GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
  string id = GridView1.DataKeys[e.RowIndex].Values[0].ToString();
  string ddluserType = ((DropDownList)row.FindControl("ddlStatus")).SelectedValue;
  SqlCommand cmdUpdate = new SqlCommand("Update Orders set OStatus = '" + ddluserType + "' where OID='" + id + "'", con);
  cmdUpdate.ExecuteNonQuery();
  con.Close();
  GridView1.EditIndex = -1;
  databind();
 }


这篇关于从gridview内的下拉列表中查找选定的文本时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆