我是第一次使用模板列。我将第一列设为模板列,在item template里面放入一个TextBox控件(是放这里的吧?)Textbox空间名为Log01001(空间名是否就是GridView里的列名呢?)然后写了一下代码
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = Session["Conn"].ToString(); string strCom = "select Log01001 from Log01";
SqlDataAdapter ada = new SqlDataAdapter(strCom, conn); DataSet Ds = new DataSet();
ada.Fill(Ds, "tt"); this.C1WebGrid1.DataSource = Ds.Tables["tt"];
this.C1WebGrid1.DataBind();
}数据并没有显示出来。请问,改怎么些那?模板列还真的没用过呢,谢谢!
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = Session["Conn"].ToString(); string strCom = "select Log01001 from Log01";
SqlDataAdapter ada = new SqlDataAdapter(strCom, conn); DataSet Ds = new DataSet();
ada.Fill(Ds, "tt"); this.C1WebGrid1.DataSource = Ds.Tables["tt"];
this.C1WebGrid1.DataBind();
}数据并没有显示出来。请问,改怎么些那?模板列还真的没用过呢,谢谢!
解决方案 »
- .NET3.5中document.getElementById().style没了?
- 刷新页面后,不保存文本框的值,有好方法大虾进来(在线等待)
- vs2005中搜索配置节点的问题
- 母版页的使用?
- 思归老大在否,高手请教一下
- asp.net 现在不调试了 高手出手啊
- [BUILD]為甚麼在VS.NET 2003中使用View In Browser或者Browser With...的時候要BUILD?
- 几个XML的问题:
- 使用C#在WebForm里使用StreamReader读取文本文件,中文变成几个乱码。
- 正则表达式匹配结果范围内再次匹配怎么写
- [VB]我后台管理的登录时间到底怎么样才能弄长啊?真晕了。
- 今年未决的最后一个问题??
((TextBox)e.Row.FindControl(控件名)).Text = 绑定数据
?
{
}protected void C1WebGrid1_DataBound(object sender, EventArgs e)
{
}
能不能将稍微写些代码,让我看看是怎么做的呢?谢谢!
{
if (e.Row.FindControl("Label1") != null)
{
string lbl = (e.Row.FindControl("Label1") as Label).Text;
lbl = DateTime.Parse(lbl).ToShortDateString();
(e.Row.FindControl("Label1") as Label).Text = lbl;
}
if (e.Row.FindControl("Label2") != null)
{
string s = (e.Row.FindControl("Label2") as Label).Text;
if (s != null && s != string.Empty)
s = DateTime.Parse(s).ToShortDateString();
(e.Row.FindControl("Label2") as Label).Text = s;
}
}
我首先要将这些数据放在datagrid里面,但是要那列隐藏然后在RowDataBound事件里面写个循环,将隐藏列的值付给textbox呢?
谢谢!
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("City") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("City") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>既然你的TemplateField是Design-Time就决定了,why not直接设置Text='<%# Bind("City") %>'
如果上面不是你所想要的简单方法,我到时候在给你一个RowDataBound处理的方法.
"City" is the filed name of data binding to that textbox
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim txtbox As TextBox
txtbox = e.Row.FindControl("txtCity")
If txtbox IsNot Nothing Then
Dim drv As Data.DataRowView
drv = CType(e.Row.DataItem, Data.DataRowView)
If drv IsNot Nothing Then
txtbox.Text = drv("city").ToString
End If
End If
End If
End Sub
End ClassLet me know if it works.
{
if (e.Row.RowType == DataControlRowType.Header || e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[0].Visible = false;
if (e.Row.FindControl("Label1") != null)
{
string lbl = (e.Row.FindControl("Label1") as Label).Text;
lbl = DateTime.Parse(lbl).ToShortDateString();
(e.Row.FindControl("Label1") as Label).Text = lbl;
} }
}
ASPX页面
<asp:TextBOX ID="Textbox1" runat="server Text='<%#Eval("tt")'%></TextBOx>
这样在你DataBind()后数据直接就填充到这里了。
如果你想对绑定的数据进行处理。。那么就需要在
RowDataBound事件中进行处理,比如我想对上面的TEXT的值加几个字
if (e.Row.RowType == DataControlRowType.Header || e.Row.RowType == DataControlRowType.DataRow)
{
TEXTBOX tt1=e.Row.findcontrol("textbox1") as TEXTBOX; //实例化对象
tt1.text= "我的值是:" +tt1.text; //将值进行处理
}
http://fenglin.xland.cn
------------------------