日期:2014-05-18  浏览次数:20427 次

如何获取gridview中定义的dropdownlist.
我现在拖了一个控件gridview,在里边有自定义的几个控件,例如:textbox,dropdownlist等,现在点击某个按钮的时候,能够取出第一行dropdownlist的选择的内容,我的代码一直有错误,一直提示"未将对象引用到实例".
前台代码为:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication5.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title></title>
</head>
<body>
  <form id="form1" runat="server">
  <div>
   
  <asp:Panel ID="Panel1" runat="server">
  <asp:Label ID="lblTableEnglishName" runat="server" Text="表格英文名称:" Font-Size="Medium"></asp:Label>
  <asp:TextBox ID="txtTableEnglishExplain" runat="server" AutoPostBack="True" Width="150px"></asp:TextBox>
  <asp:Label ID="lblTableChineseName" runat="server" Text="表格中文名称:"></asp:Label>
  <asp:TextBox ID="txtTableChineseExplain" runat="server"></asp:TextBox>
  </asp:Panel>
   
  </div>
  <asp:GridView ID="gdvTableField" runat="server" AutoGenerateColumns="false"
  OnRowDataBound="gdvTableField_RowCommand">
  <Columns>
   
  <asp:TemplateField HeaderText="中文名称">
  <ItemTemplate>
  <asp:TextBox ID="txtColumnChineseName" runat="server" AutoPostBack="true"  
  OnTextChanged="txtColumnChineseName_TextChanged">  
  
  </asp:TextBox>
  </ItemTemplate>
  </asp:TemplateField>

  <asp:TemplateField HeaderText="英文名称">
  <ItemTemplate>
  <asp:TextBox ID="txtColumnEnglishName" runat="server" AutoPostBack="true" OnTextChanged="txtColumnEnglishName_TextChanged">  
  </asp:TextBox>
  </ItemTemplate>
  </asp:TemplateField>

  <asp:TemplateField HeaderText="字段类型">
  <ItemTemplate>
  <asp:DropDownList ID="ddlFieldType" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlFieldType_SelectedIndexChanged">  
  <asp:ListItem>字符串类型</asp:ListItem>
  <asp:ListItem>数字类型</asp:ListItem>
  <asp:ListItem>时间类型</asp:ListItem>
  <asp:ListItem>文本类型</asp:ListItem>
  <asp:ListItem>小数类型</asp:ListItem>
  </asp:DropDownList>
  </ItemTemplate>
  </asp:TemplateField>

  <asp:TemplateField HeaderText="长度">
  <ItemTemplate>
  <asp:TextBox ID="txtIntegerCount" runat="server" AutoPostBack="true" OnTextChanged="txtIntegerCount_TextChanged">
  </asp:TextBox>
  </ItemTemplate>  
  </asp:TemplateField>

  <asp:TemplateField HeaderText="小数位">
  <ItemTemplate>