Hi,
Software Environment : Visual Studio 2010, Windows XP. Infragistics Web data grid 2011.1.
1) Can we add rows and columns to the web data grid at run time without binding any dataset or datatable to the webdata grid.
2) I have a grid where first 8 rows will have different set of data, which require having drop downs, textboxes, lables etc in cells.
3) From 9th row onwards, i will have a different set of data which require textboxes in grid cells.
4) If this can be done, then pls provide the code snippet for this ?
5) Also, if there is any complete E-book kind of thing for Webdata grid, then pls let me know the link for that. We are new to the webdata grid and not sure whatever approach we are taking is correct not. An e-book on Webdatagrid will help us a lot and will also help Infragistics as our support questions will also come down :)
ThanksVineet
Hello Vineet,
I will attempt to answer your questions in the order they were asked:
1. Yes, there are Unbound columns and Template columns that can be used for this purpose. These types of columns do not require Data Source to be applied to them to function correctly. More information about Unbound and Template columns you can find here - http://help.infragistics.com/Help/NetAdvantage/ASPNET/2011.1/CLR4.0/html/WebDataGrid_Columns.html How you can add columns at runtime you can see here - http://help.infragistics.com/Help/NetAdvantage/ASPNET/2011.1/CLR4.0/html/WebDataGrid_Add_or_Remove_a_Column.html
2. In this scenario you can use Template columns. In this type of columns you can insert different type of ASP and HTML controls - http://help.infragistics.com/Help/NetAdvantage/ASPNET/2011.1/CLR4.0/html/WebDataGrid_Column_Templates.html
The grid has “InitializeRow” event. This event is fired once for every row on grid initialization. It can be used to show or hide some of the controls inserted in the templates. For example:
<ig:TemplateDataField Key="Button"> <ItemTemplate> <asp:Button id="btn1" Text="test" runat="server" /> <asp:TextBox ID="tBox1" runat="server" EnableViewState="true" /> </ItemTemplate> <Header Text="ASPTextBox" /> </ig:TemplateDataField>
<ItemTemplate>
<asp:Button id="btn1" Text="test" runat="server" />
<asp:TextBox ID="tBox1" runat="server" EnableViewState="true" />
</ItemTemplate>
<Header Text="ASPTextBox" />
</ig:TemplateDataField>
protected void WebDataGrid1_InitializeRow(object sender, Infragistics.Web.UI.GridControls.RowEventArgs e) { if (e.Row.Index == 3) { Button btn = (Button)e.Row.Items[4].FindControl("btn1"); btn.Visible = false; // hides the button inserted in the template } }
{
if (e.Row.Index == 3)
Button btn = (Button)e.Row.Items[4].FindControl("btn1");
btn.Visible = false; // hides the button inserted in the template
}
3. Same as point 2 – you can hide other controls and leave only text boxes.
4. Provided in point 2.
5. Documentation for the “WebDataGrid” can be found in the following link - http://help.infragistics.com/Help/NetAdvantage/ASPNET/2011.1/CLR4.0/html/Web_WebDataGrid_WebDataGrid.html Live samples of the grid can be reviewed here - http://samples.infragistics.com/aspnet/ComponentOverview.aspx?cn=data-grid
Let me know if you have additional questions.
I created a grid as per ur suggestions. That grid is not bound to any data source. When i run the application, the grid is not visible. I want to do twot things.
1) Every time on page load, i want to display some blank rows. This means, even if there is no data in grid, i should see at least two rows in the grid.
2) On a button click I want to add rows to the grid.
Below is the code i have written in the page
.aspx Page Code:
<%
%>
<!
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
="http://www.w3.org/1999/xhtml">
="server">
>
</
="WebDataGrid1_InitializeRow">
="0">
/>
="1">
.cs File Code
protected
e)
(e.Row.Index<=5)
);
)
txtboxcontrol.Visible =
;
txtboxcontrol1.Visible =
(e.Row.Index >= 6)
ddllist.Visible =
ddllist1.Visible =
// if (e.Row.Index >= 6)
You can add row in the grid from Client-Side like shown here - http://help.infragistics.com/Help/NetAdvantage/ASPNET/2011.2/CLR4.0/html/WebDataGrid_Row_Adding.html
Sample of how to add new row you can download from the following thread - http://community.infragistics.com/forums/p/60543/308040.aspx