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>
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++;
}
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);
}
Please, tel me if i am wrong anywhere, and how can i fetch data from Gridview's Textbox