Hi,
How can i get the value of particular column in the particular row.In normal ASp gridview we can get the value by GridView.Rows(0).Cells(1).Value.ToString().Suppose i want to get the value of secondcolumn in firstrow of the child.IS dat using rowislands can we get that.?Please help me with this issue.
Regards,
Hsakarp
Hello Hsakarp,
You can get the text from the WHDG Child Column using the following code.
protected void WebHierarchicalDataGrid1_RowIslandDataBound(object sender, RowIslandEventArgs e) { ContainerGrid childGrid = this.WebHierarchicalDataGrid1.GridView.Rows[0].RowIslands[0];
string str= childGrid.Rows[0].Items[1].Text;
}
Please let me know if you have any further questions regarding this matter.
Dear Prabha!
How to get value of item template of WHDG Child Column when i submit form. I've two event RowIslandsPopulating to populating child data and RowIslandDataBound to get value data after change but when I submit form I have no value of data. I debug see detail event RowIslandsPopulating exec when I submit form and populate data and refresh child grid. Can you show me to solution
Here my Code:
<ig:WebHierarchicalDataGrid ID="WebHierarchicalDataGrid1" runat="server" AutoGenerateColumns="false" AutoGenerateBands="false" InitialExpandDepth="0" InitialDataBindDepth="0" Height="450" Width="100%" DataKeyFields="id" StyleSetName="Office2007Blue" OnPreRender="WebHierarchicalDataGrid1_PreRender" EnableViewState="False" OnRowIslandsPopulating="WebHierarchicalDataGrid1_RowIslandsPopulating" OnRowIslandDataBound="WebHierarchicalDataGrid1_RowIslandDataBound" > <ExpandCollapseAnimation SlideOpenDirection="Auto" SlideOpenDuration="300" SlideCloseDirection="Auto" SlideCloseDuration="300" /> <Columns> <ig:TemplateDataField Key="chkChon"> <ItemTemplate> <asp:CheckBox ID="chkChon" runat="server" Enabled="true" Checked="false" /> </ItemTemplate> </ig:TemplateDataField> <ig:BoundDataField Hidden="False" DataFieldName="id" Key="id"> <Header Text="id" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="code" Key="code"> <Header Text="Mã" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="name" Key="name"> <Header Text="Tên đơn vị" /> </ig:BoundDataField> </Columns> <Bands> <ig:Band Key="id" DataKeyFields="id" ShowHeader="false" AutoGenerateColumns="False"> <Columns> <ig:TemplateDataField Width="10%" Key="chkChon"> <ItemTemplate> <asp:CheckBox ID="chkChon" runat="server" Enabled="true" Checked="false" /> </ItemTemplate> </ig:TemplateDataField> <ig:BoundDataField Hidden="True" Width="20%" DataFieldName="id" Key="id" ><Header Text="Mã"></Header> </ig:BoundDataField> <ig:BoundDataField Width="20%" DataFieldName="username" Key="username" ><Header Text="Mã"></Header> </ig:BoundDataField> <ig:BoundDataField Width="35%" DataFieldName="name" Key="name" > <Header Text="Tên cán bộ"></Header> </ig:BoundDataField> <ig:BoundDataField DataFieldName="dept_name" Key="dept_name" > <Header Text="Phòng ban"></Header> </ig:BoundDataField> </Columns> </ig:Band> </Bands> </ig:WebHierarchicalDataGrid>
<asp:Button ID="cmdSave" OnClick="cmdSave_OnClick" runat="server" Text="Save" />
protected void WebHierarchicalDataGrid1_RowIslandsPopulating(object sender, ContainerRowCancelEventArgs e) { e.Cancel = true; var childGrid = new ContainerGrid(); // Get the data key string key = e.Row.DataKey[0].ToString(); var sql = @"SELECT u.[id], u.[username], u.[name], u.[branch_id], b.name AS dept_name FROM admin.[user] u INNER JOIN list.branch b ON b.id = u.unit_id INNER JOIN admin.user_group ug ON ug.[user_id] = u.id WHERE ug.group_id =" + Request.QueryString["id"] + " and u.branch_id =" + key; if (rdo1.Checked) { sql = @"SELECT u.[id], u.[username], u.[name], u.[branch_id], b.name AS dept_name FROM admin.[user] u INNER JOIN list.branch b ON b.id = u.unit_id WHERE u.branch_id =" + key; } DataSet dsTemp = DbUtil.DbUtil.get_dataset(sql); if (dsTemp != null && dsTemp.Tables[0].Rows.Count > 0) { e.Row.RowIslands.Add(childGrid); childGrid.DataSource = dsTemp; childGrid.Band = WebHierarchicalDataGrid1.Bands[0]; } if (WebHierarchicalDataGrid1.GridView.Rows[e.Row.Index].RowIslands != null && WebHierarchicalDataGrid1.GridView.Rows[e.Row.Index].RowIslands.Count > 0) { var childGrid2 = WebHierarchicalDataGrid1.GridView.Rows[e.Row.Index].RowIslands[0]; foreach (GridRecord record in childGrid2.Rows) { var c = record.Items[0].FindControl("chkChon") as CheckBox; var sql1 = @"Select count(1) as total from admin.user_group ug where ug.group_id=" + Request.QueryString["Id"] + " and ug.user_id= " + record.Items[1].Value; var a = DbUtil.DbUtil.get_datarow(sql1); if (a != null && a["total"].Equals(1) && c != null) c.Checked = true; } } }
protected void WebHierarchicalDataGrid1_RowIslandDataBound(object sender, RowIslandEventArgs e) { if (WebHierarchicalDataGrid1.GridView.Rows[0].RowIslands.Count > 0) { var childGrid2 = WebHierarchicalDataGrid1.GridView.Rows[0].RowIslands[0]; foreach (GridRecord record in childGrid2.Rows) { var c = record.Items[0].FindControl("chkChon") as CheckBox; if (c!= null && c.Checked) userListId += record.Items[1].Value + ";"; } } }
protected void cmdSave_OnClick(object sender, EventArgs e) { var session = NHibernateSessionManager.Instance.Session; try { session.BeginTransaction(); string userListId = ""; foreach (GridRecord row in WebHierarchicalDataGrid1.Rows) { var b = row.Items[0].FindControl("chkChon") as CheckBox; // Get row island using data member if (WebHierarchicalDataGrid1.GridView.Rows[row.Index].RowIslands != null && WebHierarchicalDataGrid1.GridView.Rows[row.Index].RowIslands.Count > 0) { var childGrid2 = WebHierarchicalDataGrid1.GridView.Rows[row.Index].RowIslands[0]; foreach (GridRecord record in childGrid2.Rows) { var c = record.Items[0].FindControl("chkChon") as CheckBox; if (record.Items[2].Value.Equals("thuynt.bic")) { string x = "1"; } if (c!= null && c.Checked) userListId += record.Items[1].Value + ";"; } } } if(userListId.Length > 0) { userListId = userListId.Substring(0, userListId.Length - 1); var sql = "exec acc.sp_phan_quyen_nguoi_dung_theo_nhom " + Request.QueryString["Id"] + ",'" + userListId + "'"; DbUtil.DbUtil.get_datatable(sql); } session.CommitTransaction(); lblMessage.Text = "Cập nhật thành công!"; }catch(Exception ex) { lblMessage.Text = ex.Message; session.RollbackTransaction(); } }
but WebHierarchicalDataGrid1.GridView.Rows[row.Index].RowIslands is no data