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
Gowtham
NA
516
41k
Crud Operation on Grid view using visual web part in sharep
Jan 31 2017 10:54 AM
hi,
unable to get the values to corresponding control on griview while clicking on edit event handler.
I was managed to update on sp list item value to grid view cells While clicking on update event successfully. But clicking on Grid view edit the radio button,check box,drop down value are not reflected to grid view controls.
protected void GridView1_RowEditing(object sender, System.Web.UI.WebControls.GridViewEditEventArgs e)
{
try
{
GridView1.EditIndex = e.NewEditIndex;
getData();
}
catch (Exception ex)
{
}
}
protected void GridView1_RowUpdating(object sender, System.Web.UI.WebControls.GridViewUpdateEventArgs e)
{
try
{
Label lbl = (Label)GridView1.Rows[e.RowIndex].Cells[2].FindControl("Label1");
TextBox name = (TextBox)GridView1.Rows[e.RowIndex].Cells[3].FindControl("TextBox1");
TextBox phonenumber = (TextBox)GridView1.Rows[e.RowIndex].Cells[4].FindControl("TextBox2");
TextBox address = (TextBox)GridView1.Rows[e.RowIndex].Cells[5].FindControl("TextBox3");
RadioButtonList gender = (RadioButtonList)GridView1.Rows[e.RowIndex].Cells[6].FindControl("RadioButtonList1");
if (gender.SelectedValue == "Male")
{
gender.Text = "Male";
}
else if (gender.SelectedValue =="Female")
{
gender.Text = "Female";
}
CheckBoxList chkdept = (CheckBoxList)GridView1.Rows[e.RowIndex].Cells[7].FindControl("CheckBoxList1");
DropDownList ddl = (DropDownList)GridView1.Rows[e.RowIndex].Cells[8].FindControl("DropDownList1");
string LookUpValue1 = ddl.SelectedItem.Text;
updateRow(lbl.Text, name.Text, phonenumber.Text, address.Text, gender.Text, chkdept.SelectedValue.ToString(), LookUpValue1);
GridView1.EditIndex = -1;
getData();
}
catch (Exception ex)
{
}
}
public void updateRow(string ItemID1, string name, string mobile, string add, string gend, string exp, string qual)
{
SPWeb currentWeb = SPContext.Current.Web;
SPList lst = currentWeb.Lists["Employee"];
SPListItem item = null;
item = lst.GetItemById(int.Parse(ItemID1));
currentWeb.AllowUnsafeUpdates = true;
item["Name"] = name;
item["PhoneNumber"] = mobile;
item["Address"] = add;
item["Gender"] = gend;
item["Experience"] = exp;
item["Qualification"] = qual;
item.Update();
lst.Update();
currentWeb.AllowUnsafeUpdates = false;
}
public void getData()
{
SPWeb currentWeb = SPContext.Current.Web;
SPList lst = currentWeb.Lists["Employee"];
SPListItemCollection myColl = lst.Items;
if (myColl.Count > 0)
{
GridView1.DataSource = myColl.GetDataTable();
GridView1.DataBind();
}
}
Reply
Answers (
0
)
Exporting files from SharePoint online to FTP Server
Best book for sharepoint beginner