I am a newbie using telerik in my visual estudio 2008 C# and i am trying to make a dropdownlist that update a column in my radgrid, it looks like all the texbox can update the columns.
what is weird is that it is updated on the database but in the column it doesnt so i have to stop debugging in order and then debug again so i can see the column updated.
i know there is an easy way to solve this but in the meantime while trying to solve this i wanted to use the forum to check or get solution faster.
here is the part of the radgrid that doesnt update
<telerik:GridBoundColumn ItemStyle-CssClass="UM_usertype" UniqueName="UserType" HeaderText="User Type" DataField="Type">
<HeaderStyle Width="60px"></HeaderStyle>
</telerik:GridBoundColumn>
and the web user control that has the dropdownlist
<td>Usertype:</td>
<td><asp:dropdownlist id="ddlUT" runat="server" tabindex="2" Width="127px"></asp:dropdownlist>
</td>
thanks in adv.
what is weird is that it is updated on the database but in the column it doesnt so i have to stop debugging in order and then debug again so i can see the column updated.
i know there is an easy way to solve this but in the meantime while trying to solve this i wanted to use the forum to check or get solution faster.
here is the part of the radgrid that doesnt update
<telerik:GridBoundColumn ItemStyle-CssClass="UM_usertype" UniqueName="UserType" HeaderText="User Type" DataField="Type">
<HeaderStyle Width="60px"></HeaderStyle>
</telerik:GridBoundColumn>
and the web user control that has the dropdownlist
<td>Usertype:</td>
<td><asp:dropdownlist id="ddlUT" runat="server" tabindex="2" Width="127px"></asp:dropdownlist>
</td>
thanks in adv.
5 Answers, 1 is accepted
0

Princy
Top achievements
Rank 2
answered on 31 Dec 2010, 07:59 AM
Santos,
Try to Rebind the grid after updating. Please elaborate your requirement if it doesn't help.
Thanks,
Princy.
Try to Rebind the grid after updating. Please elaborate your requirement if it doesn't help.
Thanks,
Princy.
0

Santos
Top achievements
Rank 1
answered on 01 Jan 2011, 06:37 PM
Yes, i am trying to rebind after postback with no luck so far let me see if i can post some code behind.
ok here is
protected void RadGrid_UpdateCommand(object source, GridCommandEventArgs e)
{
GridEditableItem editedItem = e.Item as GridEditableItem;
UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
//Prepare new row to add it in the DataSource
DataRow[] changedRows = this.Users.Select("idUser = " + editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["idUser"]);
if (changedRows.Length != 1)
{
UserManagement_RadGrid.Controls.Add(new LiteralControl("Unable to locate the User for updating."));
e.Canceled = true;
return;
}
//Update new values
Hashtable newValues = new Hashtable();
newValues["UserType"] = (userControl.FindControl("ddlUT") as DropDownList).SelectedIndex.ToString();
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection();
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
System.Data.SqlClient.SqlDataAdapter daSelect = new System.Data.SqlClient.SqlDataAdapter();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
try
{
//Set the SQLCommand
cmd.CommandText = @"user_update";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = conn;
cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@idUser", System.Data.SqlDbType.Int));
cmd.Parameters["@idUser"].Value = newValues["idUser"];
cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@UserType", System.Data.SqlDbType.TinyInt));
cmd.Parameters["@UserType"].Value = newValues["UserType"];
daSelect.UpdateCommand = cmd;
try
{
if (cmd.Connection.State != ConnectionState.Open)
cmd.Connection.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
throw ex;
}
//Close the connection
if (cmd.Connection.State != ConnectionState.Closed)
cmd.Connection.Close();
}
catch (Exception ex)
{
Messagestatus.Text = "Unable to insert User. Reason: Missing information";// + ex.Message
e.Canceled = true;
}
changedRows[0].BeginEdit();
try
{
foreach (DictionaryEntry entry in newValues)
{
changedRows[0][(string)entry.Key] = entry.Value;
}
changedRows[0].EndEdit();
this.Users.AcceptChanges();
// Update_DataBase();
}
catch (Exception ex)
{
changedRows[0].CancelEdit();
Messagestatus.Text = "Unable to update User. Reason: " + ex.Message;
e.Canceled = true;
}
this.UserManagement_RadGrid.MasterTableView.Rebind();
Response.Redirect("User_Management.aspx");
}
ok here is
protected void RadGrid_UpdateCommand(object source, GridCommandEventArgs e)
{
GridEditableItem editedItem = e.Item as GridEditableItem;
UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
//Prepare new row to add it in the DataSource
DataRow[] changedRows = this.Users.Select("idUser = " + editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["idUser"]);
if (changedRows.Length != 1)
{
UserManagement_RadGrid.Controls.Add(new LiteralControl("Unable to locate the User for updating."));
e.Canceled = true;
return;
}
//Update new values
Hashtable newValues = new Hashtable();
newValues["UserType"] = (userControl.FindControl("ddlUT") as DropDownList).SelectedIndex.ToString();
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection();
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
System.Data.SqlClient.SqlDataAdapter daSelect = new System.Data.SqlClient.SqlDataAdapter();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
try
{
//Set the SQLCommand
cmd.CommandText = @"user_update";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = conn;
cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@idUser", System.Data.SqlDbType.Int));
cmd.Parameters["@idUser"].Value = newValues["idUser"];
cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@UserType", System.Data.SqlDbType.TinyInt));
cmd.Parameters["@UserType"].Value = newValues["UserType"];
daSelect.UpdateCommand = cmd;
try
{
if (cmd.Connection.State != ConnectionState.Open)
cmd.Connection.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
throw ex;
}
//Close the connection
if (cmd.Connection.State != ConnectionState.Closed)
cmd.Connection.Close();
}
catch (Exception ex)
{
Messagestatus.Text = "Unable to insert User. Reason: Missing information";// + ex.Message
e.Canceled = true;
}
changedRows[0].BeginEdit();
try
{
foreach (DictionaryEntry entry in newValues)
{
changedRows[0][(string)entry.Key] = entry.Value;
}
changedRows[0].EndEdit();
this.Users.AcceptChanges();
// Update_DataBase();
}
catch (Exception ex)
{
changedRows[0].CancelEdit();
Messagestatus.Text = "Unable to update User. Reason: " + ex.Message;
e.Canceled = true;
}
this.UserManagement_RadGrid.MasterTableView.Rebind();
Response.Redirect("User_Management.aspx");
}
0

Princy
Top achievements
Rank 2
answered on 03 Jan 2011, 08:58 AM
Hello Santos,
Try try setting EnabeleViewState" to false as described in the following forum .
Rad Grid not updating with new value after update
And I hope someone from Telerik give us a hand in this issue if this does not help?
Thanks,
Princy.
Try try setting EnabeleViewState" to false as described in the following forum .
Rad Grid not updating with new value after update
And I hope someone from Telerik give us a hand in this issue if this does not help?
Thanks,
Princy.
0

Santos
Top achievements
Rank 1
answered on 04 Jan 2011, 03:50 PM
Before saying anything else i would like to say thank you so much Princy cause you are trying to help me out on this.
I just try the EnableViewState ="false" and it didnt work. i tried to do as well a response.redirect to the same page to make it update but it didnt work and with server.transfer i got an js error message.
what is really weird is that all textbox gets updated on the update function of my grip but the dropdownlist doesnt update... i am wondering if should i use dropdowncolum in order for it to work with the update?
I just try the EnableViewState ="false" and it didnt work. i tried to do as well a response.redirect to the same page to make it update but it didnt work and with server.transfer i got an js error message.
what is really weird is that all textbox gets updated on the update function of my grip but the dropdownlist doesnt update... i am wondering if should i use dropdowncolum in order for it to work with the update?
0

Santos
Top achievements
Rank 1
answered on 12 Jan 2011, 05:32 PM
I already solved the issue by using:
Session["MYSESSION"] = null;
RadGrid.MasterTableView.ClearEditItems();
RadGrid.Rebind();
that made it;
and of course i was usng griddropdowncolumn :)
Thanks
Session["MYSESSION"] = null;
RadGrid.MasterTableView.ClearEditItems();
RadGrid.Rebind();
that made it;
and of course i was usng griddropdowncolumn :)
Thanks