从gridview获取下拉列表中的值 [英] Get value in dropdownlist from gridview

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

问题描述

我编写了以下代码以在下拉列表和文本框中获取值。下拉列表是 ddlSpareParts ,文本框是 txtSPMCode 。我运行一个循环来获取gridview grdEditSparePartsMaintenance 的值,并在 ddlSpareParts txtSPMCode 中显示结果。但我在文本框中获得了价值但在下拉列表中没有获得价值。请解决问题并帮助我。

I have written the following code to get value in a dropdownlist and a textbox. The dropdownlist is "ddlSpareParts" and the textbox is "txtSPMCode" . I run a loop to get the value of gridview "grdEditSparePartsMaintenance" and show the result in ddlSpareParts and txtSPMCode . But I get value in textbox but don''t get value in dropdownlist. Please solve the problem and help me.

ddlSpareParts.Text = grdEditSparePartsMaintenance.Rows[k].Cells[2].Text.Trim();
txtSPMCode.Text = grdEditSparePartsMaintenance.Rows[k].Cells[4].Text;

推荐答案

在下拉菜单中添加值,例如

Add values in drop down like
ddlSpareParts.Items.Add(grdEditSparePartMaintenance.Rows[k].Cells[2].Text.Trim());


Hello Prince,



要从DropDownList读取值,首先需要获得控件的句柄。使用类似于下面所示的代码来检索对DropDownList的引用。然后你可以读取值。

Hello Prince,

To read the value from DropDownList you first need to get a handle on the control. Use code similar to one shown below to retrieve a reference to DropDownList. Then you can read the value.
Dim ctrl As Control
Dim row As GridViewRow
Dim ddl as DropDownList 

row = grdEditSparePartsMaintenance.Rows[k]
ctrl = row.FindControl("ddlSpareParts")
ddl = TryCast(ctrl, DropDownList)
txtSPMCode.Text = ddl.SelectedValue



问候,


Regards,


您必须在下拉列表中添加值。

例如尝试 ddlSparePart.Items.Add(grdEditSparePartsMaintenance.Rows [k] .Cells [2] .Text.Trim()
You have to add the values in the dropdown.
For e.g. try ddlSparePart.Items.Add(grdEditSparePartsMaintenance.Rows[k].Cells[2].Text.Trim().


这篇关于从gridview获取下拉列表中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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