HI all,
i have binded data from database into a stringbulider table. Is it possible to edit the stringbuilder table. If yes how can we do that. Plz help.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Guest UserRank #1,422 · 1.2K reputationPosted Jun 21, 2011, 4:11 AM EDT
Pradeep ChandrakerRank #941 · 2.2K reputationPosted Jun 21, 2011, 6:43 AM EDT
Ruchi R91 reputationPosted Jun 21, 2011, 8:52 PM EDT
Here is my code for binding data in a stringbulider. The given below code binds data in a table. Now i need to edit those data when required. How is it possible to do?
protected void bindData()
{
StringBuilder ShowDetails = new StringBuilder();
divShow.Style.Add("display", "none");
string myquery = "select sId, sEmpName, dtYear, dtMonth, sSalary from tblSalarySheet where sStatus='A' and dtYear='"+ ddListYear.SelectedItem.Text +"' and dtMonth='"+ ddlistMonth.SelectedItem.Text +"'";
int rowNum = 1;
string conn = ConfigurationSettings.AppSettings["SqlConn"];
SqlConnection MyConn = new SqlConnection(conn);
SqlCommand cmd = new SqlCommand(myquery, MyConn);
SqlDataReader reader;
try
{
MyConn.Open();
reader = cmd.ExecuteReader();
if (reader.HasRows)
{
divShow.Style.Add("display", "block");
rowNum = 1;
while (reader.Read())
{
if (rowNum % 2 == 0)
ShowDetails.Append("
else
ShowDetails.Append("
ShowDetails.Append("
ShowDetails.Append("
ShowDetails.Append("
ShowDetails.Append("
ShowDetails.Append("
ShowDetails.Append("
"");
rowNum++;
ShowDetails.Append("
}
Session["sID"] = ShowDetails.ToString();
}
else
{
divShow.Style.Add("display", "none");
}
reader.Close();
}
catch
{
}
finally
{
MyConn.Close();
cmd.Dispose();
}
}
Pradeep ChandrakerRank #941 · 2.2K reputationPosted Jun 21, 2011, 9:05 PM EDT
Also can you explain little bit more on what exactly you want to do. I see you are assigning StringBuilder variable ShowDetails into session, but wanted to know what exactly you want to edit, it will be good if you can provide some scenario.
Ruchi R91 reputationPosted Jun 21, 2011, 9:18 PM EDT
The above code binds the data from a database into a table. Now what i need to do is: there will be one edit button on a form. If a user check on a checkbox in table and Click on a edit button, he should be able to edit the respective data. Could you provide me a sample code if possible.
Pradeep ChandrakerRank #941 · 2.2K reputationPosted Jun 21, 2011, 9:32 PM EDT
Instead of using html table you need to use asp.net datagrid to provide edit functionality. Please go through below link for more details on how to implement edit/update/ delete functionality in datagrid.
http://www.c-sharpcorner.com/UploadFile/rahul4_saxena/BasicoperationsofDataGrid05022007081224AM/BasicoperationsofDataGrid.aspx
http://www.c-sharpcorner.com/UploadFile/lcamlibel/datagridwebcontrol02122007040915AM/datagridwebcontrol.aspx
http://www.codeproject.com/KB/aspnet/Edit_and_Delete_Data.aspx