using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;public partial class admin_edit_category : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        
        TextBox bigname= GridView1.FooterRow.FindControl("addbigname").c as TextBox;
        string ts = bigname.Text;
        SqlDataSource1.InsertParameters["Bigcute_name"].DefaultValue =bigname.Text;
       
        SqlDataSource1.Insert();
    }
}为什么 bigname.text的值为空的。?
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="edit_category.aspx.cs" Inherits="admin_edit_category" %><!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:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues"
            ConnectionString="<%$ ConnectionStrings:xinProductsConnectionString %>" DeleteCommand="DELETE FROM [Bigcute] WHERE [bigcute_id] = @original_bigcute_id AND [Bigcute_name] = @original_Bigcute_name"
            InsertCommand="INSERT INTO [Bigcute] ([Bigcute_name]) VALUES (@Bigcute_name)"
            OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT bigcute_id,bigcute_name FROM [Bigcute] ORDER BY [bigcute_id]"
            UpdateCommand="UPDATE [Bigcute] SET [Bigcute_name] = @Bigcute_name WHERE [bigcute_id] = @original_bigcute_id AND [Bigcute_name] = @original_Bigcute_name">
            <DeleteParameters>
                <asp:Parameter Name="original_bigcute_id" Type="Int32" />
                <asp:Parameter Name="original_Bigcute_name" Type="String" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="Bigcute_name" Type="String" />
                <asp:Parameter Name="original_bigcute_id" Type="Int32" />
                <asp:Parameter Name="original_Bigcute_name" Type="String" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="Bigcute_name" Type="String" />
            </InsertParameters>
        </asp:SqlDataSource>
        &nbsp;</div>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="bigcute_id"
            DataSourceID="SqlDataSource1" Width="50%" ShowFooter="True">
            <Columns>
                <asp:TemplateField HeaderText="bigcute_id" InsertVisible="False" SortExpression="bigcute_id">
                    <EditItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("bigcute_id") %>'></asp:Label>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("bigcute_id") %>'></asp:Label>
                    </ItemTemplate>
                    <FooterTemplate>
                        <asp:Label ID="Label3" runat="server" Text="添加新类:"></asp:Label></FooterTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Bigcute_name" SortExpression="Bigcute_name">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Bigcute_name") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("Bigcute_name") %>'></asp:Label>
                    </ItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="addbigname" runat="server"></asp:TextBox></FooterTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="操作">
                    <EditItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update"
                            Text="更新"></asp:LinkButton>
                        <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
                            Text="取消"></asp:LinkButton>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit"
                            Text="编辑"></asp:LinkButton>
                        <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Delete"
                            Text="删除"></asp:LinkButton>
                    </ItemTemplate>
                    <FooterTemplate>
                        <asp:Button ID="Button1" runat="server" Text="增加" OnClick="Button1_Click" /></FooterTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </form>
</body>
</html>

解决方案 »

  1.   

    如果用(TextBox) GridView1.FooterRow.FindControl("addbigname").c (这个c是?)
      

  2.   

    c#
    string ts = ((TexBox)GridView1.FindControl("addbigname")).Text
      

  3.   

    如何能取得空数据模板中的TextBox的ID的a的输入字符?
      

  4.   

    string ts = ((TexBox)GridView1.FindControl("a")).Text
      

  5.   

    这个TextBoxt是在gridview的<EmptyDataTemplate></EmptyDataTemplate>中的,
    不在columns里的,
    而GridView1.EmptyDataTemplate.FindControl找不到这个方法
      

  6.   

    难道在这个EmptyDataTemplate里输入的数据不能取到吗?应该可以的吧?