有这样一个问题
我有一个Gridview要绑定数据,其中一列是一个下拉框,这个下拉框有两项(两项的值分别人1,0),而且这两项都是人为加上去的,也就是说下拉框的值是固定的,但Gridview绑定值的时候,下拉框对应的列取出来的是一个值,然后要求页面登录时下拉框选中的项与读出来的值要相对应(比如说,取出来的值为0,则下拉框选中的项的值为0,反之则行踪的项的值为1) 请问这个问题怎么解决? 各位高手帮一下忙,进者有分,回春越准确,分越高。 谢谢了各位!!!!
我有一个Gridview要绑定数据,其中一列是一个下拉框,这个下拉框有两项(两项的值分别人1,0),而且这两项都是人为加上去的,也就是说下拉框的值是固定的,但Gridview绑定值的时候,下拉框对应的列取出来的是一个值,然后要求页面登录时下拉框选中的项与读出来的值要相对应(比如说,取出来的值为0,则下拉框选中的项的值为0,反之则行踪的项的值为1) 请问这个问题怎么解决? 各位高手帮一下忙,进者有分,回春越准确,分越高。 谢谢了各位!!!!
解决方案 »
- 调试部署在iis的网站的问题
- 客户端点击树形图节点时子选项如何也打上一个勾?
- 奇怪的问题: ASPX2.0 页面中文本框 tbxName 在后台文件代码中 strName = tbxName.text.trim()无法获得?
- 如何用C#语言控制excel表 使得excel的列的大小能自适应导出到里面的数据
- 发邮件程序
- datagrid 删除问题
- 这个正则表达式是什么意思,那位大虾能详细解释-----在线等
- repeater里放置的控件怎么控制属性?例如隐藏或显示
- 该怎样准备下一次面试?
- My97DatePicker 如何传值? 特定的一段日期
- 把google地图放在自己的网站,希望添加的地址标签只在自己网站看到,别的网站不能看到google官方网站也不能看到我的地点标记
- 有关上传文件的问题
/// 获取选中DataGridView的行
/// </summary>
/// <param name="dgv"></param>
/// <returns></returns>
public static System.Data.DataRow CurrentRow(DataGridView dgv)
{
System.Data.DataRowView view = null;
CurrencyManager MyCurrencyManager;
MyCurrencyManager = dgv.BindingContext[dgv.DataSource, dgv.DataMember] as CurrencyManager;
if (MyCurrencyManager.Position >= 0)
{
view = (System.Data.DataRowView)MyCurrencyManager.Current;
}
if (view != null)
{
return view.Row;
}
else
{
return null;
}
} System.Data.DataRow row = SystemManger.CurrentRow(dgvStuQK);//SystemManger是上面方法的类
int id = int.Parse(row["Id"].ToString());//得到Gridview的值
<asp:GridView runat="server" ID="gvTest">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList runat="server" ID="ddlTest">
<asp:ListItem Value="0" Selected='<%# Eval("id").ToString().Equals("0") %>'>0</asp:ListItem>
<asp:ListItem Value="1" Selected='<%# Eval("id").ToString().Equals("0") %>'>1</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
2 . RowDataBound事件中,再作一次处理 。
<asp:GridView runat="server" ID="gvTest">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList runat="server" ID="ddlTest">
<asp:ListItem Value="0" Selected='<%# Eval("id").ToString().Equals("0") %>'>0</asp:ListItem>
<asp:ListItem Value="1" Selected='<%# Eval("id").ToString().Equals("1") %>'>1</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[5].Text=="0")
{
e.Row.Cells[5].Text = "0";
}
else
{
e.Row.Cells[5].Text = "1";
}
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
DropDownList ddl = e.Row.FindControl("DropDownList1") as DropDownList;
if (ddl != null)
ddl.SelectedValue = e.Row.Cells[0].Text;
}
DropDownList ddl = new DropDownList();
Session.Add("abc", ddl.SelectedValue); //保存下拉框的值DropDownList ddlsigle = new DropDownList();//登陆页的下拉框
ddlsigle.ClearSelection();
ddlsigle.Items.FindByValue(Session["abc"].ToString()).Selected = true;
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[5].Text=="0")
{
e.Row.Cells[5].Text = "0";
}
else
{
e.Row.Cells[5].Text = "1";
}
}
}
{
int index = e.NewEditIndex;
DropDownList drop = (DropDownList)ViewUsers.Rows[index].Cells["下拉框所在列索引"].FindControl("DropDownList1");
drop.DataSource = 数据源(data());
drop.DataTextField = "Name";
drop.DataValueField = "Id";
drop.DataBind();
drop.SelectedIndex = data().Rows[index]["与下拉框对应的列"].ToString();
}
if (e.Row.RowType == DataControlRowType.DataRow)
this.ddl.SelectedValue=你取出来的值,看是0还是1了,要是字符串,如"1".
这样就行了.
{
DropDownList ddl = e.Row.FindControl("DropDownList1") as DropDownList;
if (ddl != null)
ddl.SelectedValue = e.Row.Cells[0].Text;
}