无法从嵌套在数据列表控件中的gridview的文本框中获取值 [英] Can't Fetch the value from textbox in gridview which is nested in datalist control
问题描述
在绑定到数据列表的gridview上工作时出现问题.
我正在一个矩阵中构建一个输入表单,该表单依赖于两个表.
在表上获取行,在其他表上获取列.
像这样:
-------------------------------------------------- ----------------
------------ |-Col1-- | --- Col2 --- | --- Col3 --- | --Col4 ---
-------------------------------------------------- ------------------
行名1 |文字框|文字框|文字框|文字框
-------------------------------------------------- ----------------
行名2 |文字框|文字框|文字框|文字框
-------------------------------------------------- ----------------
行名3 |文字框|文字框|文字框|文字框
-------------------------------------------------- ----------------
行名4 |文字框|文字框|文字框|文字框
-------------------------------------------------- ----------------
行名5 |文字框|文字框|文字框|文字框
-------------------------------------------------- ----------------
这是我用于构建此布局的代码
I have a problem when working on gridview which is binded in a datalist.
I am building a input form in a matrix from which is depend on two tables.
on table for rows and other table for columns.
like this:
------------------------------------------------------------------
------------ |-- Col1--| ---Col2--- | ---Col3--- | --Col4---
--------------------------------------------------------------------
Rowname1 | Textbox | Textbox | Textbox | Textbox
------------------------------------------------------------------
Rowname2 | Textbox | Textbox | Textbox | Textbox
------------------------------------------------------------------
Rowname3 | Textbox | Textbox | Textbox | Textbox
------------------------------------------------------------------
Rowname4 | Textbox | Textbox | Textbox | Textbox
------------------------------------------------------------------
Rowname5 | Textbox | Textbox | Textbox | Textbox
------------------------------------------------------------------
this is my code for building this layout
<asp:DataList ID="DataList1" runat="server" OnItemDataBound="DataList1_ItemDataBound"
Width="490px" RepeatDirection="Horizontal" BorderWidth="1px">
<ItemTemplate>
<table>
<tr>
<td>
<table border="1px">
<tr>
<td style="text-align: center">
<asp:Label ID="Label1" CssClass="floa" runat="server" Text='<%#Eval("Branch_name") %>'></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" ShowHeader="false"
BorderStyle="None">
<Columns>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%#Eval("Affiliate") %>' Width="150px"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Value(%)">
<ItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" CssClass="text"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
我正在使用Gidview进行输入,并将其水平绑定到数据列表中
这是将这个gridview绑定到数据列表中的代码:-
I am using Gidview for input which is binded in datalist horizontly
This is my code for binding this gridview inside datalist:--
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
GridView gv = (GridView)e.Item.FindControl("GridView1");
if (gv != null)
{
gv.DataSource = s.Tables[1];
gv.DataBind();
if (i != 1)
{
gv.Columns[0].Visible = false;
}
i++;
}
此控件内部的此网格视图的绑定正常工作;但是
当我想从gridview控件的文本框中获取数据时,我无法获取它.
表示我可以成功找到对提交"按钮的单击的控制.但是我无法从gridview控件的文本框中找到已编辑的更改数据.
这是我对提交"按钮的点击的编码
The binding of this gridview inside this control is working properly; but
when i want to fetch data from the textbox of gridview control i can''t get it.
means I successfuly find the control on submit button''s click. But i can''t able to find the edited changed data from the textbox from gridview control.
this is my coding for submit button''s click
protected void Button1_Click(object sender, EventArgs e)
{
GridView gv = (GridView)DataList1.Items[0].Controls[1].FindControl("GridView1");
int i = gv.Rows.Count;
string t = ((TextBox)gv.Rows[1].FindControl("DataList1_ctl00_GridView1_ctl03_TextBox3")).Text;
Response.Write(t);
}
请在任何地方出错的情况下给我打电话,以及如何从Gridview的Textbox中获取数据?
}
Please, tel me if i am wrong anywhere, and how can i fetch data from Gridview''s Textbox
推荐答案
您可以从gridview或数据列表嵌套控件及其控件中找到服务器端ID,而不是客户端ID.像这样在findcontrol中更改您的ID
you can find from gridview or datalist nested control with its server side id not client-side id. change your id in findcontrol like this
protected void Button1_Click(object sender, EventArgs e)
{
GridView gv = (GridView)DataList1.Items[0].Controls[1].FindControl("GridView1");
int i = gv.Rows.Count;
string t = ((TextBox)gv.Rows[1].FindControl("TextBox3")).Text;
Response.Write(t);
}
这篇关于无法从嵌套在数据列表控件中的gridview的文本框中获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!