用gridview中的值填充文本框 [英] fill the textbox with values in gridview
本文介绍了用gridview中的值填充文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在gridview中用今天的日期填充文本框中的值?
文本框位于gridview内..
我正在使用asp.net,c#,VS2005和sql server 2005
再次感谢你...
问候
karan
how i can fill the values in textbox with today''s date in gridview?
textbox is present inside the gridview..
i am using asp.net,c#,VS2005 and sql server 2005
thnk u once again...
regards
karan
推荐答案
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
onrowdatabound="GridView1_RowDataBound" >
<Columns>
<asp:TemplateField HeaderText="First">
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Second">
<ItemTemplate>
<asp:DropDownList ID="ddl_BindValues" DataValueField="Name" runat="server">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Third">
<ItemTemplate>
<asp:TextBox ID="TextBox2" Text='<%#Eval("id") %>' runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Fourth">
<ItemTemplate>
<asp:TextBox ID="TextBox3" Text='<%#Eval("name") %>' runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Fifth">
<ItemTemplate>
<asp:TextBox ID="TextBox4" Text='<%#Eval("Price") %>' runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" HeaderText="Edit" />
</Columns>
</asp:GridView>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGrid();
}
}
public void BindGrid()
{
Con = new SqlConnection("Connection string");
Con.Open();
dt = new SqlDataAdapter("Select * from Your Table ", Con);
DataSet ds = new DataSet();
dt.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
Con.Close();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
TextBox txt1 = (TextBox)e.Row.FindControl("TextBox1");
txt1.Text = DateTime.Now.ToString();
}
}
<big>I hope now you can solve that</big></i>
currTextbox.Text = DateTime.Now.ToString();
在行级找到文本框,然后编写上面的代码行!
您需要使用 GridView RowDataBound [ ^ ]事件方法以获取行级别的访问权限.
尝试!?
currTextbox.Text = DateTime.Now.ToString();
Find the textbox at row level and just write the above code line!
You need to use GridView RowDataBound[^] event method in order to get access at row level.
Try!?
卡兰·约书亚,
我认为您可以使用以下代码:
Hi karan joshua,
I think you can use this code :
dataGridView1[ColumnIndex, RowIndex].Value = DateTime.Now.ToString();
其中ColumnIndex和RowIndex是整数值,用于定义要编辑的单元格的索引.
希望对您有所帮助,
:)
where ColumnIndex and RowIndex are integer values defining the index of the cell to be editted.
I hope this help,
:)
这篇关于用gridview中的值填充文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文