TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ajit kush
NA
45
1.2k
Grouping Data In gridview1 for edit on ID based
Mar 24 2017 4:10 AM
i want to make group in grid view as ID for update with help of sql server.
but not create.
my code is.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
gvbind();
}
}
protected void gvbind()
{
con.Open();
SqlCommand cmd = new SqlCommand("Select * from shopDetails1", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
if (ds.Tables[0].Rows.Count > 0)
{
GridView1.DataSource = ds;
GridView1.DataBind();
ShowGrpDataInGridView(GridView1.Rows, 0, 18);
}
else
{
ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
GridView1.DataSource = ds;
GridView1.DataBind();
int columncount = GridView1.Rows[0].Cells.Count;
GridView1.Rows[0].Cells.Clear();
GridView1.Rows[0].Cells.Add(new TableCell());
GridView1.Rows[0].Cells[0].ColumnSpan = columncount;
GridView1.Rows[0].Cells[0].Text = "No Records Found";
}
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());
GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
Label lblID = (Label)row.FindControl("lblID");
// TextBox txtname=(TextBox)row.cell[].control[0];
TextBox txtstore = (TextBox)row.Cells[1].Controls[0];
TextBox txtmobile = (TextBox)row.Cells[2].Controls[0];
TextBox txtD_form_type = (TextBox)row.Cells[3].Controls[0];
TextBox txtD_Lic_no = (TextBox)row.Cells[4].Controls[0];
TextBox txtD_validfrom = (TextBox)row.Cells[5].Controls[0];
TextBox txtD_validupto = (TextBox)row.Cells[6].Controls[0];
TextBox txtL_validfrom = (TextBox)row.Cells[7].Controls[0];
TextBox txtL_validUpto = (TextBox)row.Cells[8].Controls[0];
TextBox txtS_validfrom = (TextBox)row.Cells[9].Controls[0];
TextBox txtS_validupto = (TextBox)row.Cells[10].Controls[0];
TextBox txtHealthreg = (TextBox)row.Cells[11].Controls[0];
TextBox txtH_validfrom = (TextBox)row.Cells[12].Controls[0];
TextBox txtH_validupto = (TextBox)row.Cells[13].Controls[0];
TextBox txtFoodreg = (TextBox)row.Cells[14].Controls[0];
TextBox txtF_validfrom = (TextBox)row.Cells[15].Controls[0];
TextBox txtF_validupto = (TextBox)row.Cells[16].Controls[0];
GridView1.EditIndex = -1;
con.Open();
//SqlCommand cmd = new SqlCommand("SELECT * FROM shopDetails1", conn);
SqlCommand cmd = new SqlCommand("update shopDetails1 set store='" + txtstore.Text + "',mobile='" + txtmobile.Text + "',D_form_type='" + txtD_form_type.Text + "',D_Lic_no='" + txtD_Lic_no.Text + "',D_validupto='" + txtD_validupto.Text + "',L_validfrom='" + txtL_validfrom.Text + "',L_validUpto='" + txtL_validUpto.Text + "',S_validfrom='" + txtS_validfrom.Text + "',S_validupto='" + txtS_validupto + "',Healthreg ='" + txtHealthreg + "',H_validfrom='" + txtH_validfrom + "',H_validupto='" + txtH_validupto + "',Foodreg='" + txtFoodreg + "',F_Validfrom='" + txtF_validfrom + "',F_validupto='" + txtF_validupto + "' where id='" + Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString()) + "'", con);
cmd.ExecuteNonQuery();
con.Close();
gvbind();
}
void ShowGrpDataInGridView(GridViewRowCollection gridViewRows, int startIndex, int totalColumns)
{
if (totalColumns == 0) return;
// int id = Convert.ToInt32(GridView1.DataKeys[].Value.ToString());
int i, count = 0;
ArrayList ast = new ArrayList();
ast.Add(gridViewRows[0]);
var ctrl = gridViewRows[0].Cells[startIndex];
for (i = 1; i < gridViewRows.Count; i++)
{
TableCell nextTbCell = gridViewRows[i].Cells[startIndex];
if (ctrl.Text == nextTbCell.Text)
{
count++;
nextTbCell.Visible = false;
ast.Add(gridViewRows[i]);
}
else
{
if (count > 0)
{
ctrl.RowSpan = count;
ShowGrpDataInGridView(new GridViewRowCollection(ast), startIndex + 1, totalColumns - 1);
}
count = 0;
ast.Clear();
ctrl = gridViewRows[i].Cells[startIndex];
ast.Add(gridViewRows[i]);
}
}
if (count > 0)
{
ctrl.RowSpan = count;
ShowGrpDataInGridView(new GridViewRowCollection(ast), startIndex + 1, totalColumns - 1);
}
count = 0;
ast.Clear();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
Label lbldeleteid = (Label)row.FindControl("lblID");
con.Open();
SqlCommand cmd = new SqlCommand("Delete FROM shopDetails1 where id='" + Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString()) + "'", con);
cmd.ExecuteNonQuery();
con.Close();
gvbind();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
gvbind();
}
i want this type of grouping but not do ..please help me
ID
Shop
Mobile No
License in Form
Drug License No
Drug Valid From
Drug Valid Upto
Leave Valid From
Leave Valid Upto
Shop Registration No
Shop Valid From
Shop Valid Upto
Health Registration No
Health Valid From
Health Valid Upto
Food Registration No
Food Valid From
Food Valid Upto
1
Ashirwad
9208580103
20
MH-MZ3-62876
06/11/12
05/11/17
29/10/12
20/10/17
760291643
01/01/15
16/12/15
887637160
07/10/15
06/10/16
21512012001229
13/12/12
04/12/17
Add/: 1/68, Ground Floor , Vinay Building,
20C
MH-MZ3-62871
06/11/12
05/11/17
Tilak Road, Ghatkopar east,Mumbai -400077/
21
MH-MZ3-62872
06/11/12
05/11/17
20B
MH-MZ3-62878
06/11/12
05/11/17
20D
MH-MZ3-62881
06/11/12
05/11/17
21B
MH-MZ3-62879
06/11/12
05/11/17
2
Vishwas/ Kiran
9870003901
20
MH-MZ3-71623
26/03/13
25/03/18
12/03/13
11/03/18
760402194
04/07/14
31/12/16
887539610
06/05/14
05/05/15
301502181228128
24/02/15
23/02/20
Add/: Shop No/5, Amrutkunj , Anjariawadi,
20C
MH-MZ3-71625
26/03/13
25/03/18
M G Road, Ghotkopar east, Mumbai-400077/
21
MH-MZ3-71624
26/03/13
25/03/18
3
Powai
968536541
20
MH-MZ4-74034
03/05/13
02/05/18
11/02/13
10/02/18
760472571
19/05/16
18/05/19
-
-
-
301502211549512
24/02/15
23/02/20
Add/ : Shop No/9, Pearl Building , Gem Powai
20C
MH-MZ4-74036
03/05/13
02/05/18
Vihar Complex, Powai, Mumbai 400076
21
MH-MZ4-74035
03/05/13
02/05/18
4
Ambika 1
986523541
20
MH-MZ3-68747
06/02/13
05/02/18
17/12/12
16/12/17
760402177
07/07/05
16/12/16
887536087
12/03/14
11/03/15
21515040000014
13/04/15
12/04/20
Add/: Shop No/14, Ambika Darshan Building,
20C
MH-MZ3-68749
06/02/13
05/02/18
43, Mahatma Gandhi Road, Ghatkopar (E ),
21
MH-MZ3-68748
06/02/13
05/02/18
Mumbai 400077
Reply
Answers (
1
)
Problem dropdown with checkbox by bootstrap multiselect
how to refresh page using back button click in mvc?