日期:2014-05-18 浏览次数:20818 次
<%="课程"+int.parse(Eval("t1").ToString()).ToString()%>
------解决方案--------------------
在后台绑定时候控制,
先申明个全局变量id,绑定一次后让id++;
再找到gridview上的控件赋值给它就可以了。
如:
int id=1;
protected void grid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
Label lbl=(Label)e.Items.FondContros["Label1"];
lbl.Text="课程:"+id;
id++;
}
------解决方案--------------------
你可以改改
string cmdstr = "select id,Uname,Upwd,CreatTime from Users"; string connstr = @" server =**;database = ** ; uid = sa; pwd = sa"; try { SqlDataAdapter oda = new SqlDataAdapter(cmdstr, connstr); DataSet ds = new DataSet(); oda.Fill(ds, "test"); dataGridView1.DataSource = ds.Tables[0].DefaultView; dataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;//设置标题文本位置 dataGridView1.DefaultCellStyle.ForeColor = Color.Blue;//设置前景色 dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing; //设置列标头高度 dataGridView1.ColumnHeadersHeight = 35;//设置列标头高度 dataGridView1.RowsDefaultCellStyle.WrapMode = DataGridViewTriState.True;//设置列文本自动换行 dataGridView1.Columns[0].ToolTipText = "ID"; dataGridView1.Columns[1].ToolTipText = "用户帐号"; dataGridView1.Columns[2].ToolTipText = "用户密码"; dataGridView1.Columns[3].ToolTipText = "创建日期"; dataGridView1.Columns[0].HeaderCell.Value = "ID"; dataGridView1.Columns[0].Width = Convert.ToInt16(0); dataGridView1.Columns[0].ReadOnly = true; dataGridView1.Columns[1].HeaderCell.Value = "帐 号"; dataGridView1.Columns[1].Width = Convert.ToInt16(70); dataGridView1.Columns[2].HeaderCell.Value = "密 码"; dataGridView1.Columns[2].Width = Convert.ToInt16(70); dataGridView1.Columns[3].HeaderCell.Value = "创建日期"; dataGridView1.Columns[3].Width = Convert.ToInt16(100); dataGridView1.Columns[3].ReadOnly = true; } catch { MessageBox.Show("读取失败.....", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error); }
------解决方案--------------------
<asp:TemplateField HeaderText="userpwd">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("userpwd") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("userpwd") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>