`
ch_kexin
  • 浏览: 875686 次
  • 性别: Icon_minigender_2
  • 来自: 青岛
社区版块
存档分类
最新评论

怎样在GridView中的DropDownList选项改变的时候获取GridView中的DataKeys.Value的二种方法:

    博客分类:
  • .NET
 
阅读更多
【1】
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" DataKeyNames="ID" >  
    <Columns>  
        <asp:TemplateField>  
          <ItemTemplate>  
              <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"   
                  onselectedindexchanged="DropDownList1_SelectedIndexChanged" >  
                 <asp:ListItem Text="选项1" Value="1001" Selected="False" ></asp:ListItem>  
                 <asp:ListItem Text="选项2" Value="1002" Selected="False"></asp:ListItem>  
                 <asp:ListItem Text="选项3" Value="1003" Selected="False"></asp:ListItem>  
                 <asp:ListItem Text="选项4" Value="0" Selected="False"></asp:ListItem>                           
              </asp:DropDownList>  
           </ItemTemplate>  
        </asp:TemplateField>                 
        <asp:BoundField ShowHeader="true" DataField="ID" HeaderText="ID" />  
        <asp:BoundField ShowHeader="true" DataField="name" HeaderText="姓名" />  
    </Columns>  
</asp:GridView>


protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)  
    {  
        DropDownList DropDownList1 = sender as DropDownList;  
        int index = (DropDownList1.NamingContainer as GridViewRow).RowIndex; 
        string id = GridView1.DataKeys[index].Value.ToString();  
/////////////////////////////////////////////////////////////////////////////////////////
4   DropDownList drp = sender as DropDownList; // 触发事件的 DropDownList
5    GridViewRow row = drp.NamingContainer as GridViewRow; // GridView 当前行 即时在dropdownlist所在容器里 就是行的信息    
6    row.Style.Add(HtmlTextWriterStyle.BackgroundColor, drp.SelectedValue);
7    Response.Write(row.RowIndex+1);//获取dropdownlist中选定行的行号.
8        //Response.Write(String.Format("选中第 {0} 行", row.RowIndex + 1));
9     DropDownList ddlClass = (DropDownList)sender;
10     string ClassID = ddlClass.SelectedValue.ToString();//获取Dropdownlist中选定值

    }

【2】

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" ABCD='<%# Eval("primary_field") %>'> 

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)  
  {  
       DropDownList dr = sender as DropDownList;  
       string keyValue=dr.Attributes["ABCD"];  
       //根据keyValue进行处理。  
  }   
分享到:
评论

相关推荐

    GridView控件中DropDownList控件的绑定

    GridView控件中DropDownList控件的绑定

    gridview与dropdownlist组合用法 asp.net

    gridview与dropdownlist组合,用的挺好,在gridview中实现数据交互.

    Gridview用法大总结配 实例(源码)说明

    1:在Gridview中无须编写后台代码,直接实现增除删改 2:在Gridview中添加新记录 3:在Gridview中实现编辑和更新操作 4:在Gridview中实现一次性更新所有记录 5:在Gridview中固定表头的实现 6:在...

    Gridview用法大总结

    1:在Gridview中无须编写后台代码,直接实现增除删改 2:在Gridview中添加新记录 3:在Gridview中实现编辑和更新操作 4:在Gridview中实现一次性更新所有记录 5:在Gridview中固定表头的实现 6:在...

    GridView用法总结大全

    1:在Gridview中无须编写后台代码,直接实现增除删改 2:在Gridview中添加新记录 3:在Gridview中实现编辑和更新操作 4:在Gridview中实现一次性更新所有记录 5:在Gridview中固定表头的实现 6:在...

    gridview72版绝技

    7.鼠标移到GridView某一行时改变该行的背景色方法二: 8.GridView实现删除时弹出确认对话框: 9.GridView实现自动编号: 10.GridView实现自定义时间货币等字符串格式: 11.GridView实现自定义时间货币等字符串格式...

    gridview中将dropdownlist中的Value赋给lebal

    gridview中将dropdownlist中的Value赋给lebal

    ASP.NET中dropdownlist和GridView控件的用法

    ASP.NET中dropdownlist和GridView控件的用法,简单易学,一看就懂.

    GridView和DropDownList结合

    GridView和下拉菜单DropDownList结合,在gridview中使用dropdownlist

    GridView和下拉菜单DropDownList结合

    ddl = (DropDownList)GridView1.Rows[i].FindControl("depList"); ddl.SelectedValue = ds.Tables[0].Rows[i]["DepId"].ToString(); ddl = (DropDownList)GridView1.Rows[i].FindControl("roleList"); ddl....

    Gridview And DropDownList.wmv

    DropDownList结合GridView的实例,DropDownList如何赋值,或是在GridView编辑时,DropDownList是如何取到原值。 本影片Size:6284KB;长度:0:13:59

    获取gridview中数据及添加dropdownlist

    获取gridview中数据及添加dropdownlist,在DataGridView中添加下拉菜单,实现DropDownlist功能

    GridView动态绑定+DropDownList

    实现GridView动态列,以及使用模板添加DropDownList,在点击编辑后整行的DropDownList显示出来。

    在GridView中使用DropDownList模板列.doc

    适合初学者学

    GridView大全

    7.鼠标移到GridView某一行时改变该行的背景色方法二: 14 8.GridView实现删除时弹出确认对话框: 15 9.GridView实现自动编号: 15 10.GridView实现自定义时间货币等字符串格式: 17 前台代码: 18 11.GridView实现用...

    GridView的19种操作

    7.鼠标移到GridView某一行时改变该行的背景色方法二 8.GridView实现删除时弹出确认对话框 9.GridView实现自动编号 10.GridView实现自定义时间货币等字符串格式 11.GridView实现用“...”代替超长字符串

    GridView空间的使用方法

    GridView空间中的各种使用方法,包括GridView无代码分页排序 GridView选中,编辑,取消,删除 GridView正反双向排序 GridView和下拉菜单DropDownList结合 GridView和CheckBox结合 鼠标移到GridView某一行时改变该行...

    C# GridView 76种绝技必杀

    鼠标移到GridView某一行时改变该行的背景色方法二 GridView实现删除时弹出确认对话框 GridView实现自动编号 GridView实现自定义时间货币等字符串格式 GridView实现用“...”代替超长字符串 GridView一般换行与强制...

    获取GridView中Checkbox的值

    获取GridView中Checkbox的值

Global site tag (gtag.js) - Google Analytics