GridView中的DropDown SelectedValue [英] DropDown SelectedValue In GridView
问题描述
我在gridview中有一个下拉菜单.我将其绑定到gridviewrowdatabound事件.问题是在我有复选框的同一gridview中.选中复选框后,我将为该行选择下拉列表的选定值.复选框自动发布事件为true.但是每次我得到第一个值时,当我在按钮上单击绑定此gridview时,我都不明白为什么每次在ui上更改它时,每次选择的值都相同的原因.
这是我的checkboxcheckchange事件代码
i have a drop down in gridview. i am binding it on gridviewrowdatabound event. The problem is in the same gridview i have checkbox. When checkbox is checked i am taking the selected value of dropdown for that row. The checkbox autopost event is true. But each time i am getting the first value where as i am binding this gridview on a button click i dont understand why each time selected value is same where i have change it on ui.
here is my code for checkboxcheckchange event
protected void chkDynamic_CheckedChanged(object sender, EventArgs e)
{
MessageCollection validationErrors = new MessageCollection();
IabolMgmtSIOBO abolMgmt = new IabolMgmtSIOBO();
UserBO user = (UserBO)Session["CurrentUser"];
Message Msg = new Message();
Msg.Text = "";
foreach (GridViewRow gr in gvMain.Rows)
{
CheckBox chkSel = (CheckBox)gr.FindControl("chkSel");
DropDownList ddlService = (DropDownList)gr.FindControl("ddlService");
if (chkSel != null && ddlService != null)
{
if (chkSel.Checked == true)
{
if (ddlService.SelectedItem.Value == "" || ddlService.SelectedItem.Value==null)
{
Msg.Text = "Select Service From DropDown First";
validationErrors.Add(Msg);
Master.ErrorMessages.Messages = validationErrors;
return;
}
else
{
abolMgmt.AssignCustomRates(CurrentUser.LoginName, CurrentUser.Password, "237", int.Parse(ddlService.SelectedItem.Value), int.Parse(gvMain.DataKeys[gr.RowIndex].Value.ToString()));
}
}
}
}
推荐答案
也许这会有所帮助 DataGridDemo [ ^ ]
Perhaps this will help DataGridDemo[^]
这篇关于GridView中的DropDown SelectedValue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!