<asp:GridView ID="gvccedetails" runat="server" AutoGenerateColumns="false" CssClass="table">
<AlternatingRowStyle CssClass="success" />
<HeaderStyle CssClass="warning" />
<SelectedRowStyle CssClass="active" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" Text="Edit" runat="server" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"
OnCommand="btnSelect_Click" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="cceid" HeaderText="CCE ID" />
<asp:BoundField DataField="ccename" HeaderText="CCE Name" />
<asp:BoundField DataField="ccecontact" HeaderText="CCE Contact" />
<asp:BoundField DataField="cceemail" HeaderText="CCE Email" />
<asp:BoundField DataField="ccesharedyn" HeaderText="Shared Resources Y/N" />
<asp:TemplateField HeaderText="Working Days">
<ItemTemplate>
<asp:CheckBoxList ID="cbl_cceworkingDays" RepeatDirection="Horizontal" runat="server"
EnableViewState="true">
<asp:ListItem Text="Mon" Value="Mon"></asp:ListItem>
<asp:ListItem Text="Tue" Value="Tue"></asp:ListItem>
<asp:ListItem Text="Wed" Value="Wed"></asp:ListItem>
<asp:ListItem Text="Thu" Value="Thu"></asp:ListItem>
<asp:ListItem Text="Fri" Value="Fri"></asp:ListItem>
<asp:ListItem Text="Sat" Value="Sat"></asp:ListItem>
<asp:ListItem Text="Sun" Value="Sun"></asp:ListItem>
</asp:CheckBoxList>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ccecentreid" HeaderText="" HeaderStyle-CssClass="hiddenColumn"
ItemStyle-CssClass="hiddenColumn" />
</Columns>
</asp:GridView>
private void fillGrid()
{
try
{
string[] items = null;
strSql = " select distinct CCE_ID,CCE_WORKINGDAYS,cce_centreno, em_first_name ||' '|| em_middle_name ||' '|| em_last_name empname," +
" EM_EMAIL, to_char( EM_DS_CELL_NO) EM_DS_CELL_NO, EM_EMPCODE,DM_ID,dm_desc " +
" from id_cce_details,ID_EMPMST,id_deptmst " +
" where cce_centreno='" + hdnCenterID.Value + "' and EM_DEPT_ID = DM_ID and EM_EMPCODE=CCE_ID ";
if (con.State != ConnectionState.Open) con.Open();
DataSet ds = cls.Get_DataSet(strSql, con);
if (ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
DataRow[] drs = ds.Tables[0].Select("cce_centreno='" + hdnCenterID.Value + "' and CCE_ID='" + ds.Tables[0].Rows[i]["CCE_ID"].ToString() + "' ");
if (drs.Length > 0)
{
strWorkDays = "";
drGrid = dtGrid.NewRow();
drGrid["ccecentreid"] = drs[0]["CCE_CENTRENO"].ToString();
drGrid["cceid"] = drs[0]["CCE_ID"].ToString();
drGrid["ccename"] = drs[0]["empname"].ToString();
drGrid["ccecontact"] = drs[0]["EM_DS_CELL_NO"].ToString();
drGrid["cceemail"] = drs[0]["EM_EMAIL"].ToString();
drGrid["ccedepartment"] = drs[0]["dm_desc"].ToString();
for (int j = 0; j < drs.Length; j++)
{
strWorkDays += drs[j]["CCE_WORKINGDAYS"].ToString() + ",";
i++;
}
drGrid["cceworkingdays"] = strWorkDays;
dtGrid.Rows.Add(drGrid);
}
}
ViewState["dtGrid"] = dtGrid;
dtGridmodified = dtGrid.DefaultView.ToTable(true);
gvccedetails.DataSource = dtGridmodified;
gvccedetails.DataBind();
for (int j = 0; j < gvccedetails.Rows.Count; j++)
{
CheckBoxList c = (CheckBoxList)gvccedetails.Rows[j].FindControl("cbl_cceworkingDays");
if (c != null)
{
items = null;
items = dtGrid.Rows[j]["cceworkingdays"].ToString().Split(',');
for (int i = 0; i < c.Items.Count; i++)
{
if (items.Contains(c.Items[i].Value))
{
c.Items[i].Selected = true;
}
}
}
}
}
else lblError.Text = "No record found";
}
catch (Exception ex)
{
lblError.Text = ex.Message;
}
}
<AlternatingRowStyle CssClass="success" />
<HeaderStyle CssClass="warning" />
<SelectedRowStyle CssClass="active" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" Text="Edit" runat="server" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"
OnCommand="btnSelect_Click" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="cceid" HeaderText="CCE ID" />
<asp:BoundField DataField="ccename" HeaderText="CCE Name" />
<asp:BoundField DataField="ccecontact" HeaderText="CCE Contact" />
<asp:BoundField DataField="cceemail" HeaderText="CCE Email" />
<asp:BoundField DataField="ccesharedyn" HeaderText="Shared Resources Y/N" />
<asp:TemplateField HeaderText="Working Days">
<ItemTemplate>
<asp:CheckBoxList ID="cbl_cceworkingDays" RepeatDirection="Horizontal" runat="server"
EnableViewState="true">
<asp:ListItem Text="Mon" Value="Mon"></asp:ListItem>
<asp:ListItem Text="Tue" Value="Tue"></asp:ListItem>
<asp:ListItem Text="Wed" Value="Wed"></asp:ListItem>
<asp:ListItem Text="Thu" Value="Thu"></asp:ListItem>
<asp:ListItem Text="Fri" Value="Fri"></asp:ListItem>
<asp:ListItem Text="Sat" Value="Sat"></asp:ListItem>
<asp:ListItem Text="Sun" Value="Sun"></asp:ListItem>
</asp:CheckBoxList>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ccecentreid" HeaderText="" HeaderStyle-CssClass="hiddenColumn"
ItemStyle-CssClass="hiddenColumn" />
</Columns>
</asp:GridView>
private void fillGrid()
{
try
{
string[] items = null;
strSql = " select distinct CCE_ID,CCE_WORKINGDAYS,cce_centreno, em_first_name ||' '|| em_middle_name ||' '|| em_last_name empname," +
" EM_EMAIL, to_char( EM_DS_CELL_NO) EM_DS_CELL_NO, EM_EMPCODE,DM_ID,dm_desc " +
" from id_cce_details,ID_EMPMST,id_deptmst " +
" where cce_centreno='" + hdnCenterID.Value + "' and EM_DEPT_ID = DM_ID and EM_EMPCODE=CCE_ID ";
if (con.State != ConnectionState.Open) con.Open();
DataSet ds = cls.Get_DataSet(strSql, con);
if (ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
DataRow[] drs = ds.Tables[0].Select("cce_centreno='" + hdnCenterID.Value + "' and CCE_ID='" + ds.Tables[0].Rows[i]["CCE_ID"].ToString() + "' ");
if (drs.Length > 0)
{
strWorkDays = "";
drGrid = dtGrid.NewRow();
drGrid["ccecentreid"] = drs[0]["CCE_CENTRENO"].ToString();
drGrid["cceid"] = drs[0]["CCE_ID"].ToString();
drGrid["ccename"] = drs[0]["empname"].ToString();
drGrid["ccecontact"] = drs[0]["EM_DS_CELL_NO"].ToString();
drGrid["cceemail"] = drs[0]["EM_EMAIL"].ToString();
drGrid["ccedepartment"] = drs[0]["dm_desc"].ToString();
for (int j = 0; j < drs.Length; j++)
{
strWorkDays += drs[j]["CCE_WORKINGDAYS"].ToString() + ",";
i++;
}
drGrid["cceworkingdays"] = strWorkDays;
dtGrid.Rows.Add(drGrid);
}
}
ViewState["dtGrid"] = dtGrid;
dtGridmodified = dtGrid.DefaultView.ToTable(true);
gvccedetails.DataSource = dtGridmodified;
gvccedetails.DataBind();
for (int j = 0; j < gvccedetails.Rows.Count; j++)
{
CheckBoxList c = (CheckBoxList)gvccedetails.Rows[j].FindControl("cbl_cceworkingDays");
if (c != null)
{
items = null;
items = dtGrid.Rows[j]["cceworkingdays"].ToString().Split(',');
for (int i = 0; i < c.Items.Count; i++)
{
if (items.Contains(c.Items[i].Value))
{
c.Items[i].Selected = true;
}
}
}
}
}
else lblError.Text = "No record found";
}
catch (Exception ex)
{
lblError.Text = ex.Message;
}
}
How do we get hdnCenterID.Value?
ReplyDeleteinstead you can consider, dropdownlist.selectedValue
ReplyDelete