DataGridView绑定后如何设置下拉框的索引,让它选中某一项?
2010-09-21 15:24
507 查看
DataGridView里有一ComboBox列,绑定后如何设置下拉框的索引,让它选中某一项?
DataGridViewComboBoxCell设置它的Value
DataGridViewComboBoxCell cb = (DataGridViewComboBoxCell)dataGridView1.Rows[0].Cells[0];
cb.Value = "2 ";
前台加个模板列隐藏起来绑定ID
<asp:TemplateField Visible= "False ">
<ItemTemplate>
<asp:CheckBox ID= "CheckBox1 " runat= "server " />
<asp:Label ID= "MyName " runat= "server " Text= ' <%#Eval( "ID字段 ") %> '> </asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField ButtonType= "Button " CausesValidation= "false " HeaderText= "编辑列 " Text= "编辑 "
CommandName= "Select ">
<ItemStyle HorizontalAlign= "Center " />
</asp:ButtonField>
<asp:ButtonField ButtonType= "Button " CausesValidation= "false " HeaderText= "删除列 " Text= "删除 "
CommandName= "Delete ">
<ItemStyle HorizontalAlign= "Center " />
</asp:ButtonField>
台直接在RowCommand事件里取
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Select ")
{
int index = Convert.ToInt32(e.CommandArgument);
Label lbl = (Label)GridView1.Rows[index].FindControl( "MyName ");
ShowData(int.Parse(lbl.Text));
}
else if (e.CommandName == "Delete ")
{
int index = Convert.ToInt32(e.CommandArgument);
Label lbl = (Label)GridView1.Rows[index].FindControl( "MyName ");
col.Delete(int.Parse(lbl.Text));
PageLoad();
}
}
ShowData(int.Parse(lbl.Text));
col.Delete(int.Parse(lbl.Text));
PageLoad();
都是自己的方法..
int index = Convert.ToInt32(e.CommandArgument);
Label lbl = (Label)GridView1.Rows[index].FindControl( "MyName ");
lbl.text就可以取出ID值
DataGridViewComboBoxCell设置它的Value
DataGridViewComboBoxCell cb = (DataGridViewComboBoxCell)dataGridView1.Rows[0].Cells[0];
cb.Value = "2 ";
前台加个模板列隐藏起来绑定ID
<asp:TemplateField Visible= "False ">
<ItemTemplate>
<asp:CheckBox ID= "CheckBox1 " runat= "server " />
<asp:Label ID= "MyName " runat= "server " Text= ' <%#Eval( "ID字段 ") %> '> </asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField ButtonType= "Button " CausesValidation= "false " HeaderText= "编辑列 " Text= "编辑 "
CommandName= "Select ">
<ItemStyle HorizontalAlign= "Center " />
</asp:ButtonField>
<asp:ButtonField ButtonType= "Button " CausesValidation= "false " HeaderText= "删除列 " Text= "删除 "
CommandName= "Delete ">
<ItemStyle HorizontalAlign= "Center " />
</asp:ButtonField>
台直接在RowCommand事件里取
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Select ")
{
int index = Convert.ToInt32(e.CommandArgument);
Label lbl = (Label)GridView1.Rows[index].FindControl( "MyName ");
ShowData(int.Parse(lbl.Text));
}
else if (e.CommandName == "Delete ")
{
int index = Convert.ToInt32(e.CommandArgument);
Label lbl = (Label)GridView1.Rows[index].FindControl( "MyName ");
col.Delete(int.Parse(lbl.Text));
PageLoad();
}
}
ShowData(int.Parse(lbl.Text));
col.Delete(int.Parse(lbl.Text));
PageLoad();
都是自己的方法..
int index = Convert.ToInt32(e.CommandArgument);
Label lbl = (Label)GridView1.Rows[index].FindControl( "MyName ");
lbl.text就可以取出ID值
相关文章推荐
- c#中DataGridView 如何设置 才能选中一行 设置鼠标事件
- jquery如何设置select索引选中
- DropDownList绑定数据源后,如何设置选中项
- QT QTableWidget设置了多行选中后,如何获取所有选中行的索引
- C#中DataGridView绑定了DataTable后,通过代码修改DataGridView中的数据,总有一行(被修改过并被用户选中的行集合中索引为0的行)不能被UpDate回数据库的问题和解决办法
- DataGridView绑定到一个DataTable时,如何设置能把空格去掉?
- 如何在Linux路由上设置IP和MAC绑定?
- C# WinForm 设置DataGridView选中指定行
- WPF中,如何将绑定源设置到单件实例
- 数据库学习(2):索引如何设置
- 三层交换机如何设置IP-MAC绑定?跨网段IP-MAC绑定方案。
- Pandas 如何去除、取消已经设置好的索引
- 来自MSDN的一个Sample:如何自定义 Windows 窗体 DataGridView 控件中的数据格式设置
- 如何设置input实现同时选中多个文件并同时上传
- [VB.NET]VB2005,DataGridView如何设置当前的单元格里的内容处于编辑状态.
- 【转】GridView如何设置选中项高亮,直到选中其他项时取消高亮
- DataGrid编辑时让DropDownList绑定数据库中某项表并设置默认选中
- [WPF]如何正确地用代码设置ListBox的当前选中项
- Js如何控制GriView中RadioButton的只能选中一项的操作
- jquery 如何设置下拉框隐藏