当前位置:编程学习 > C#/ASP.NET >>

取得DataList中控件的值

点击按钮时将datalist控件中的值取出来提交,现在的问题是能取到datalist里面的控件但是不能取到控件的值。调试发现值是空的。 --------------------编程问答-------------------- 贴下代码看看 --------------------编程问答-------------------- 代码问题 --------------------编程问答-------------------- Page_Load

if(!IsPostBack)
{
   //数据绑定
} --------------------编程问答--------------------   foreach (DataListItem d in dtSmallTask.Items)
        {
            TextBox txtSendTo1 = (TextBox)d.FindControl("txtSendTo");
            string txtsendTovalue=txtSendTo1.Text;
        }
发现为空值在提交前txtSendTo有内容的,注意提交的按钮并不在dtSmallTask的模板内。所以ItemCommand之类的东西没考虑。请高手指教 --------------------编程问答-------------------- 至于if (!IsPostBack)
        {}这个存在的控件是找得到的但是就是取不到模板里面控件的值 --------------------编程问答--------------------
引用 5 楼 zhangyoucai19881030 的回复:
至于if (!IsPostBack)
        {}这个存在的控件是找得到的但是就是取不到模板里面控件的值

你的模版里的控件有值吗?
用findcontrol取不到?
demo
 protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandSource.GetType() == typeof(Button))
        {
                if (((Button)e.CommandSource).CommandName == "accept")
                {
                    if (((CheckBox)e.Item.FindControl("select")).Checked)
                    {

                    int id = Convert.ToInt32(DataList1.DataKeys[e.Item.ItemIndex].ToString());
                    int stuid = Convert.ToInt32(((Label)e.Item.FindControl("label1")).Text);
                    string stuname = ((Label)e.Item.FindControl("label2")).Text;
                    string stuadd = ((Label)e.Item.FindControl("label3")).Text;
                    SqlConnection cn = new SqlConnection(strcon);
                    SqlCommand cmd = new SqlCommand("insert into s(StuID,StuName,Stuaddurl) values('" + stuid + "','" + stuname + "','" + stuadd + "')", cn);
                    cn.Open();
                    cmd.ExecuteNonQuery();
                    SqlCommand cmd1 = new SqlCommand("delete from students where ID='" + id + "'", cn);
                    cmd1.ExecuteNonQuery();
                    cn.Close();
                    bind();
                    }
                }
                if (((Button)e.CommandSource).CommandName == "noaccept")
                {
                    if (((CheckBox)e.Item.FindControl("select")).Checked)
                    {
                    int id = Convert.ToInt32(DataList1.DataKeys[e.Item.ItemIndex].ToString());
                    int stuid = Convert.ToInt32(((Label)e.Item.FindControl("label1")).Text);
                    string stuname = ((Label)e.Item.FindControl("label2")).Text;
                    string stuadd = ((Label)e.Item.FindControl("label3")).Text;
                    SqlConnection cn = new SqlConnection(strcon);
                    SqlCommand cmd = new SqlCommand("insert into sj(stuid,stuname,stuadd) values('" + stuid + "','" + stuname + "','" + stuadd + "')", cn);
                    cn.Open();
                    cmd.ExecuteNonQuery();
                    SqlCommand cmd1 = new SqlCommand("delete from students where ID='" + id + "'", cn);
                    cmd1.ExecuteNonQuery();
                    cn.Close();
                    bind();
                }
            }
        }
--------------------编程问答-------------------- 回复6楼:
对模板里面控件存在值。但是我提交的按钮并不在datalist这个控件里面也就是说我点击按钮的作用是循环找datalist里面控件的值并对数据进行数据库操作。至于ItemCommand事件应该是触发不到的。 --------------------编程问答-------------------- <%@ Page Language="C#" AutoEventWireup="true" EnableViewState ="false" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

 EnableViewState ="false" 有没有在页面或配置文件设置这个 --------------------编程问答--------------------

<%@ Page Language="C#" AutoEventWireup="true" EnableViewState ="false" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!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:DataList ID="DataList1" runat="server">
           <ItemTemplate>
            <table>
              <asp:TextBox ID="txt" runat="server" Text='<%#Eval("Name") %>'></asp:TextBox>
            </table>
           </ItemTemplate>
        </asp:DataList>
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
    </div>
    </form>
</body>
</html>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn("Name"));
            dt.Rows.Add(new object[] { "River" });
            dt.Rows.Add(new object[] { "China" });
            DataList1.DataSource = dt;
            DataList1.DataBind();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        foreach (DataListItem item in DataList1.Items)
        {
            TextBox tb = (TextBox)item.FindControl("txt");
            Response.Write(tb.Text);
        }
    }
}

--------------------编程问答-------------------- 把Page命令中的 EnableViewState ="false" 删除 --------------------编程问答-------------------- 这个EnableViewState ="false"没有之前我也找过。 --------------------编程问答-------------------- 代码贴出来看看。。。


<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table style="border-collapse:collapse;" border=1>
            <asp:DataList ID="DataList1" runat="server">
                <ItemTemplate>
                    <tr>
                        <td>
                            <%#Eval("EmpID") %>
                        </td>
                        <td>
                           <asp:TextBox ID="txtName" runat="server" Text=<%#Eval("EmpName")%>></asp:TextBox>  
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:DataList>
        </table>
        <asp:Button ID="Button1" runat="server" Text="提交" onclick="Button1_Click" />
    </div>
    </form>
</body>
</html>




public class Employee
        {
            public string EmpID { set; get; }
            public string EmpName { set; get; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.DataList1.DataSource = new System.Collections.Generic.List<Employee>()
                { 
                      new Employee(){ EmpID="S001", EmpName="张三"},
                      new Employee(){ EmpID="S002", EmpName="李四"},
                      new Employee(){ EmpID="S003", EmpName="王五"},
                      new Employee(){ EmpID="S004", EmpName="赵六"},
                      new Employee(){ EmpID="S005", EmpName="小七"}
                };
                this.DataList1.DataBind();
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string message = string.Empty;
            foreach (DataListItem item in this.DataList1.Items)
            {
                TextBox tx = item.FindControl("txtName") as TextBox;
                if (!string.IsNullOrEmpty(tx.Text))
                {
                    message += tx.Text + "|";
                }
            }
            Response.Write(message.TrimEnd('|'));   //输出信息
        }
--------------------编程问答-------------------- 按实例来说的话我的和八楼的代码差不多但是八楼的EnableViewState ="false"去掉后点击按钮提交的时候能取到文本框的值吗? --------------------编程问答--------------------
引用 13 楼 zhangyoucai19881030 的回复:
按实例来说的话我的和八楼的代码差不多但是八楼的EnableViewState ="false"去掉后点击按钮提交的时候能取到文本框的值吗?


可以的 --------------------编程问答--------------------  后台代码:   protected void btnSubmit_Click(object sender, EventArgs e)
    {
        foreach (DataListItem d in dtSmallTask.Items)
        {
            TextBox txtSendTo = (TextBox)d.FindControl("txtSendTo");            
            TextBox hdnTxtSendTo = (TextBox)d.FindControl("hdnTxtSendTo");
            TextBox txtCcTo = (TextBox)d.FindControl("txtCcTo");
            TextBox hdnTxtCcTo = (TextBox)d.FindControl("hdnTxtCcTo");
            TextBox txtBccTo = (TextBox)d.FindControl("txtBccTo");
            TextBox hdnTxtBccTo = (TextBox)d.FindControl("hdnTxtBccTo");
            TextBox txtstartTime = (TextBox)d.FindControl("txtstartTime");
            TextBox txtendTime = (TextBox)d.FindControl("txtendTime");
            CheckBox ckman1 = (CheckBox)d.FindControl("ckman1");
            CheckBox ckman2 = (CheckBox)d.FindControl("ckman2");
            CheckBox ckman3 = (CheckBox)d.FindControl("ckman3");
            CheckBox ckman4 = (CheckBox)d.FindControl("ckman4");
            CheckBox ckmsg1 = (CheckBox)d.FindControl("ckmsg1");
            CheckBox ckmsg2 = (CheckBox)d.FindControl("ckmsg2");
            CheckBox ckmsg3 = (CheckBox)d.FindControl("ckmsg3");
            CheckBox CheckBox1 = (CheckBox)d.FindControl("CheckBox1");
            CheckBox CheckBox2 = (CheckBox)d.FindControl("CheckBox2");
            CheckBox CheckBox3 = (CheckBox)d.FindControl("CheckBox3");
            TextBox txtTaskContent = (TextBox)d.FindControl("txtTaskContent");
            SqlParameter[] para =
                     {
                     new SqlParameter("@ZongRenWuBianHao",txtAllTaskID.Text ),
                     new SqlParameter("@RenWuBianHao",txtAllTaskName.Text ),
                     new SqlParameter("@FuZeRen",txtSendTo.Text ),
                     new SqlParameter("@StrFuZeRen",hdnTxtSendTo.Text ),
                     new SqlParameter("@XieBanRen",txtCcTo.Text ),
                     new SqlParameter("@StrXieBanRen",hdnTxtCcTo.Text ),
                     new SqlParameter("@CanYueRen",txtBccTo.Text ),
                     new SqlParameter("@StrCanYueRen",hdnTxtBccTo.Text ),
                     new SqlParameter("@KaiShiShiJian",txtstartTime.Text ),
                     new SqlParameter("@JieShuShiJian",txtendTime.Text ),
                     new SqlParameter("@TiXingFangShi1", ckman1.Checked == true ? "1" : "0"),
                     new SqlParameter("@TiXingFangShi2", ckman2.Checked == true ? "1" : "0"),
                     new SqlParameter("@TiXingFangShi3", ckman3.Checked == true ? "1" : "0"),
                     new SqlParameter("@TiXingFangShi4", ckman4.Checked == true ? "1" : "0"),
                     new SqlParameter("@FaSongFangShi1",ckmsg1.Checked == true ? "1" : "0"),
                     new SqlParameter("@FaSongFangShi2",ckmsg2.Checked == true ? "1" : "0"),
                     new SqlParameter("@FaSongFangShi3",ckmsg3.Checked == true ? "1" : "0"),
                     new SqlParameter("@TiXingSheZhi1",CheckBox1.Checked == true ? "1" : "0"),
                     new SqlParameter("@TiXingSheZhi2",CheckBox2.Checked == true ? "1" : "0"),
                     new SqlParameter("@TiXingSheZhi3",CheckBox3.Checked == true ? "1" : "0"),
                     new SqlParameter("@RenWuLeiRong",""),
                     new SqlParameter("@FuJian","")
                
                      };

            bs.Execute("Proc_Zong_FenRenWu_InsertORUpdate2", para);
        } --------------------编程问答-------------------- 前台代码? --------------------编程问答--------------------  太多了发少点吧应该可以看的 <asp:DataList ID="dtSmallTask" runat="server" Width="901px" OnItemCommand="dtSmallTask_ItemCommand" >
                            <ItemTemplate>
                                <table border="0" cellpadding="0" cellspacing="0" style="width: 100%; border-right: #3399cc 2px dashed; border-top: #3399cc 2px dashed; border-left: #3399cc 2px dashed; border-bottom: #3399cc 2px dashed;">
                                    <tr>
                                        <td class="ItemTitleFont" style="width: 114px; height: 30px;">
                                            <strong>
                        会务分项:</strong></td>
                                        <td style="width: 536px; height: 30px;">
                                            <asp:TextBox ID="txtSmallTaskNM" runat="server" CssClass="InputStyle" Height="18px"
                                                  TabIndex="1"
                                                Width="230px" ReadOnly="True" Text='<%# Eval("RenWuMingCheng") %>'></asp:TextBox>
                                            <asp:TextBox ID="txtSmallTaskID"   runat="server" CssClass="InputStyle" Height="18px"   ReadOnly="True" TabIndex="1" Width="52px" Text='<%# Eval("RenWuBianHao") %>'></asp:TextBox>
                                            <asp:TextBox ID="rowitemname" runat="server" Text="<%#(Container).ItemIndex + 1%>" CssClass="InputStyle" Height="18px" Width="84px" Visible="False"></asp:TextBox></td>
                                    </tr>
                                    <tr>
                                        <td class="ItemTitleFont" style="width: 114px; height: 36px;">
                                            负责人:</td>
                                        <td style="width: 536px; height: 36px;">
                                            <asp:TextBox ID="txtSendTo" runat="server" CssClass="InputStyle" Height="30px" 
                                                 TabIndex="1" TextMode="MultiLine" Width="292px"  value="<%=SendToRealName%>" name="txtSendTo" ></asp:TextBox> 
                                            <a style="CURSOR: hand"  onclick="dialwinprocess(<%#(Container).ItemIndex%>)"  href="javascript:void(0);">添加人员</a><asp:TextBox ID="hdnTxtSendTo" runat="server"
                                                        CssClass="InputStyle" Height="18px" TabIndex="1" TextMode="MultiLine" Width="154px"  value="<%=SendTo%>" name="hdnTxtSendTo" Text='<%# Eval("FuZeRen") %>'></asp:TextBox></td>
                                    </tr>
                                    <tr>
                                        <td class="ItemTitleFont" style="width: 114px; height: 30px;">
                                            协办人:</td>
                                        <td style="width: 536px; height: 30px;">
                                            <asp:TextBox ID="txtCcTo" runat="server" CssClass="InputStyle" Height="30px" TabIndex="1" TextMode="MultiLine" Width="292px"  value="<%=CcToRealName%>" name="txtCcTo" Text='<%# Eval("StrXieBanRen") %>'></asp:TextBox> 
                                            <a onclick="window.open('AddMenber.aspx', 'newwindow', 'height=520, width=515, top=150, left=400, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no')"><span
                                                    style="text-decoration: underline; cursor: hand;"></span></a><asp:TextBox ID="hdnTxtCcTo" runat="server"
                                                CssClass="InputStyle" Height="18px" TabIndex="1" TextMode="MultiLine" Width="154px"   value="<%=CcTo%>" name="hdnTxtCcTo" Text='<%# Eval("XieBanRen") %>'></asp:TextBox></td>
                                    </tr>
                                    <tr>
                                        <td class="ItemTitleFont" style="width: 114px; height: 30px;">
                                            参阅人:</td>
                                        <td style="width: 536px; height: 30px;">
                                            <asp:TextBox ID="txtBccTo" runat="server" CssClass="InputStyle" Height="30px"  TabIndex="1" TextMode="MultiLine" Width="292px" value="<%=BccToRealName%>" name="txtBccTo" Text='<%# Eval("StrCanYueRen") %>' ></asp:TextBox> 
                                            <a onclick="window.open('AddMenber.aspx', 'newwindow', 'height=520, width=515, top=150, left=400, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no')"><span
                                                    style="text-decoration: underline; cursor: hand;"><asp:TextBox ID="hdnTxtBccTo" runat="server"
                                                        CssClass="InputStyle" Height="18px" TabIndex="1" TextMode="MultiLine" Width="154px"   value="<%=BccTo%>" name="hdnTxtBccTo" Text='<%# Eval("CanYueRen") %>'></asp:TextBox></span></a></td>
                                    </tr>
                                    <tr>
                                        <td class="ItemTitleFont" style="width: 114px; height: 30px">
                                            任务时间设置:</td>
                                        <td style="width: 536px; height: 30px">
                                            <asp:TextBox ID="txtstartTime" runat="server" CssClass="inputdate"  Height="16px" name="txtstartTime" onclick="setday(this)"  ReadOnly="True" TabIndex="3" Width="154px" Text='<%# Eval("KaiShiShiJian") %>'></asp:TextBox>
                                            至 
                                            <asp:TextBox ID="txtendTime" runat="server" CssClass="inputdate" Height="16px" name="txtendTime" onclick="setday(this)" ReadOnly="True" TabIndex="3" Width="154px" Text='<%# Eval("JieShuShiJian") %>'></asp:TextBox></td>
                                    </tr>
                                    <tr style="color: #004779">
                                        <td class="ItemTitleFont" style="width: 114px; height: 30px">
                                            提醒接受人设置:</td>
                                        <td style="width: 536px; height: 30px" valign="middle"><asp:CheckBox ID="ckman1" runat="server" Text="发布人" Checked='<%# Eval("TiXingFangShi1").ToString()=="1" ? true:false %>' />
                                            <asp:CheckBox ID="ckman2" runat="server" Text="责任人" Checked='<%# Eval("TiXingFangShi2").ToString()=="1" ? true:false %>' />
                                            <asp:CheckBox ID="ckman3" runat="server" Text="协办人" Checked='<%# Eval("TiXingFangShi3").ToString()=="1" ? true:false %>' />
                                            <asp:CheckBox ID="ckman4" runat="server" Text="参阅人" Checked='<%# Eval("TiXingFangShi4").ToString()=="1" ? true:false %>' />

                                </table>
                            </ItemTemplate>
                        </asp:DataList> --------------------编程问答--------------------   <asp:DataList ID="dtSmallTask" runat="server" Width="901px" OnItemCommand="dtSmallTask_ItemCommand" >
                            <ItemTemplate>
                                <table border="0" cellpadding="0" cellspacing="0" style="width: 100%; border-right: #3399cc 2px dashed; border-top: #3399cc 2px dashed; border-left: #3399cc 2px dashed; border-bottom: #3399cc 2px dashed;">
                                    <tr>
                                        <td class="ItemTitleFont" style="width: 114px; height: 30px;">
                                            <strong>
                        会务分项:</strong></td>
                                        <td style="width: 536px; height: 30px;">
                                            <asp:TextBox ID="txtSmallTaskNM" runat="server" CssClass="InputStyle" Height="18px"
                                                  TabIndex="1"
                                                Width="230px" ReadOnly="True" Text='<%# Eval("RenWuMingCheng") %>'></asp:TextBox>
                                            <asp:TextBox ID="txtSmallTaskID"   runat="server" CssClass="InputStyle" Height="18px"   ReadOnly="True" TabIndex="1" Width="52px" Text='<%# Eval("RenWuBianHao") %>'></asp:TextBox>
                                            <asp:TextBox ID="rowitemname" runat="server" Text="<%#(Container).ItemIndex + 1%>" CssClass="InputStyle" Height="18px" Width="84px" Visible="False"></asp:TextBox></td>
                                    </tr>
                                    <tr>
                                        <td class="ItemTitleFont" style="width: 114px; height: 36px;">
                                            负责人:</td>
                                        <td style="width: 536px; height: 36px;">
                                            <asp:TextBox ID="txtSendTo" runat="server" CssClass="InputStyle" Height="30px" 
                                                 TabIndex="1" TextMode="MultiLine" Width="292px"  value="<%=SendToRealName%>" name="txtSendTo" ></asp:TextBox> 
                                            <a style="CURSOR: hand"  onclick="dialwinprocess(<%#(Container).ItemIndex%>)"  href="javascript:void(0);">添加人员</a><asp:TextBox ID="hdnTxtSendTo" runat="server"
                                                        CssClass="InputStyle" Height="18px" TabIndex="1" TextMode="MultiLine" Width="154px"  value="<%=SendTo%>" name="hdnTxtSendTo" Text='<%# Eval("FuZeRen") %>'></asp:TextBox></td>
                                    </tr>
                                    <tr>
                                        <td class="ItemTitleFont" style="width: 114px; height: 30px;">
                                            协办人:</td>
                                        <td style="width: 536px; height: 30px;">
                                            <asp:TextBox ID="txtCcTo" runat="server" CssClass="InputStyle" Height="30px" TabIndex="1" TextMode="MultiLine" Width="292px"  value="<%=CcToRealName%>" name="txtCcTo" Text='<%# Eval("StrXieBanRen") %>'></asp:TextBox> 
                                            <a onclick="window.open('AddMenber.aspx', 'newwindow', 'height=520, width=515, top=150, left=400, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no')"><span
                                                    style="text-decoration: underline; cursor: hand;"></span></a><asp:TextBox ID="hdnTxtCcTo" runat="server"
                                                CssClass="InputStyle" Height="18px" TabIndex="1" TextMode="MultiLine" Width="154px"   value="<%=CcTo%>" name="hdnTxtCcTo" Text='<%# Eval("XieBanRen") %>'></asp:TextBox></td>
                                    </tr>
                                    <tr>
                                        <td class="ItemTitleFont" style="width: 114px; height: 30px;">
                                            参阅人:</td>
                                        <td style="width: 536px; height: 30px;">
                                            <asp:TextBox ID="txtBccTo" runat="server" CssClass="InputStyle" Height="30px"  TabIndex="1" TextMode="MultiLine" Width="292px" value="<%=BccToRealName%>" name="txtBccTo" Text='<%# Eval("StrCanYueRen") %>' ></asp:TextBox> 
                                            <a onclick="window.open('AddMenber.aspx', 'newwindow', 'height=520, width=515, top=150, left=400, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no')"><span
                                                    style="text-decoration: underline; cursor: hand;"><asp:TextBox ID="hdnTxtBccTo" runat="server"
                                                        CssClass="InputStyle" Height="18px" TabIndex="1" TextMode="MultiLine" Width="154px"   value="<%=BccTo%>" name="hdnTxtBccTo" Text='<%# Eval("CanYueRen") %>'></asp:TextBox></span></a></td>
                                    </tr>
                                    <tr>
                                        <td class="ItemTitleFont" style="width: 114px; height: 30px">
                                            任务时间设置:</td>
                                        <td style="width: 536px; height: 30px">
                                            <asp:TextBox ID="txtstartTime" runat="server" CssClass="inputdate"  Height="16px" name="txtstartTime" onclick="setday(this)"  ReadOnly="True" TabIndex="3" Width="154px" Text='<%# Eval("KaiShiShiJian") %>'></asp:TextBox>
                                            至 
                                            <asp:TextBox ID="txtendTime" runat="server" CssClass="inputdate" Height="16px" name="txtendTime" onclick="setday(this)" ReadOnly="True" TabIndex="3" Width="154px" Text='<%# Eval("JieShuShiJian") %>'></asp:TextBox></td>
                                    </tr>
                                    <tr style="color: #004779">
                                        <td class="ItemTitleFont" style="width: 114px; height: 30px">
                                            提醒接受人设置:</td>
                                        <td style="width: 536px; height: 30px" valign="middle"><asp:CheckBox ID="ckman1" runat="server" Text="发布人" Checked='<%# Eval("TiXingFangShi1").ToString()=="1" ? true:false %>' />
                                            <asp:CheckBox ID="ckman2" runat="server" Text="责任人" Checked='<%# Eval("TiXingFangShi2").ToString()=="1" ? true:false %>' />
                                            <asp:CheckBox ID="ckman3" runat="server" Text="协办人" Checked='<%# Eval("TiXingFangShi3").ToString()=="1" ? true:false %>' />
                                            <asp:CheckBox ID="ckman4" runat="server" Text="参阅人" Checked='<%# Eval("TiXingFangShi4").ToString()=="1" ? true:false %>' />

                                </table>
                            </ItemTemplate>
                        </asp:DataList>

        
--------------------编程问答--------------------

            发多了次不好意思
        
--------------------编程问答--------------------

            看下,原来你是说多行文本框取不到值
你按如下方法给多行文本框赋值

   protected void dtSmallTask_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            TextBox tb = (TextBox)e.Item.FindControl("txtSendTo");
            tb.Text = ((DataRowView)e.Item.DataItem)["Name"].ToString();
        }
    }
--------------------编程问答-------------------- 看了下IHandler的实例估计还是我的代码有问题,估计脚本里面清空掉了,仔细看下到时候不管怎样回复下大家。 --------------------编程问答-------------------- 好的我试下 --------------------编程问答-------------------- <asp:TextBox ID="txtSendTo" runat="server" CssClass="InputStyle" Height="30px"  
  TabIndex="1" TextMode="MultiLine" Width="292px" value="<%=SendToRealName%>" name="txtSendTo" ></asp:TextBox>

value="<%=SendToRealName%>" 不要用Value了,用Text --------------------编程问答-------------------- 还是不行。 --------------------编程问答-------------------- 也还是不行。 --------------------编程问答--------------------
引用 24 楼 zhangyoucai19881030 的回复:
还是不行。

我看这些代码没啥问题了
控件都取不到值,还是检查下配置文件有没有做全局enableviewstate设置,并在本页面page命令加上 EnableViewState="true"

另外,其它页面没有这样的问题? --------------------编程问答-------------------- 估计也是那样现在很久没用这块了记得之前好像都没问题的。估计还是代码里面那个地方有问题吧 --------------------编程问答-------------------- 有没有用新的母版页,模板页是否EnableViewState = "false" --------------------编程问答-------------------- 没有设置 --------------------编程问答--------------------
引用 29 楼 zhangyoucai19881030 的回复:
没有设置

那就休息,明天再调试,可能豁然开朗 --------------------编程问答-------------------- 也是,但是这个东西搞不好,我就睡都睡不着。这还是头一次调试那么就居然找不到原因。那我从新写一次试下看看到底哪里有问题。 --------------------编程问答--------------------
引用 31 楼 zhangyoucai19881030 的回复:
也是,但是这个东西搞不好,我就睡都睡不着。这还是头一次调试那么就居然找不到原因。那我从新写一次试下看看到底哪里有问题。


写个原型试试 --------------------编程问答-------------------- 问题解决答案已于昨晚解决:我用的脚本对其进行datalist中的控件进行赋值,而且本身datalist中生成的控件为客户端控件所以如果在提交的时候服务器端时判断该控件的值是空的,是用脚本找到该控件对应的clientid在从中去取值。 --------------------编程问答-------------------- http://blog.csdn.net/xianfajushi/archive/2008/11/30/3413317.aspx --------------------编程问答--------------------
引用 9 楼 IHandler 的回复:
XML/HTML code?1234567891011121314151617181920212223<%@ Page Language="C#" AutoEventWireup="true" EnableViewState ="false" CodeFile="Default2.aspx.cs" Inherits="Default2" %> <!DOCTYPE html……

取DataList中某一项中的某个控件的值,这样是吧所以项的值都取出来了!
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,