如何在网格视图中获得动态创建的下拉所选文本 [英] How to get dynamic created dropdown selected text in grid view

查看:96
本文介绍了如何在网格视图中获得动态创建的下拉所选文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我需要在gridview中找到动态创建的下拉列表的选定文本.请帮忙.

Hi,
I need to find selected text of dynamically created dropdown in gridview.Please help.

推荐答案

首先,您必须动态创建一个下拉列表并将其添加到gridview编辑临时字段中在gridview行中创建的事件

然后在行命令事件中找到像
这样的dropdownlis控件
First you have to create a dropdown list dynamically and add it to gridview edit tempalte field in gridview row created event

then on row command event find that dropdownlis control like
If e.CommandName = "Edit" Then
          Dim i As Integer = e.CommandArgument
          Dim row As GridViewRow = GridView2.Rows(i)

                  Dim dd As DropDownList       
   dd= DirectCast(row.FindControl("ddl1"), DropDownList)
           

      End If



可能会帮助您



it may help you


尝试此操作,首先获取一个模板字段,然后添加项目模板,然后在编辑模板内部将下拉列表如下...


try this ,first take a template field then add item template,then inside edit template put the dropdown as follow...


<asp:templatefield headertext="Status" sortexpression="with_status" xmlns:asp="#unknown">
                    <itemtemplate>
                        <asp:label id="Label1" runat="server" text="<%# Bind("with_status") %>"></asp:label>
                    </itemtemplate>

                    <edititemtemplate>
                        <asp:dropdownlist id="DropDownList1" runat="server">
                        <asp:listitem value="0">-Select- </asp:listitem>
                        <asp:listitem value="1">pending </asp:listitem>
                      <asp:listitem value="2">completed </asp:listitem>

                        </asp:dropdownlist>
                    </edititemtemplate>
                </asp:templatefield>




aspx.cs

在rowupdating上输入以下代码




aspx.cs

on rowupdating put the following code

DropDownList ddl2 = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("DropDownList1");
            if (ddl2.SelectedValue.ToString() != "0")
            {
                SqlDataSource1.UpdateParameters["with_status"].DefaultValue = ddl2.SelectedItem.ToString();
 
            }


这篇关于如何在网格视图中获得动态创建的下拉所选文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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