Rad网格编辑 [英] Rad Grid Editing

查看:85
本文介绍了Rad网格编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,

我正在使用RadGrid,其中我正在使用数据集作为数据源并将完整的数据库表带到网格上.我在Button Select上使用Buttoned进行网格的编辑,删除和保存,并在网格下创建了一个asp:Panel显示用于编辑所选行的值的文本框.现在,我的asp:panel包含2个按钮,保存和取消.

我的问题是:-
所选行的值显示在面板上的文本框中以供编辑,编辑后,当我单击保存"时,我已隐藏该面板,但值未保存在该行中.除非发生回发,如我选择另一行然后单击编辑",然后单击页面回发",以前编辑的行现在将在gridRow中显示已编辑的值.

我没有使用Grid的Need Data Suorces事件.是否必须使用?
如果是这样,在我的情况下,实现它的正确方法是什么?

这是我的代码-

受保护的void SaveChanges_Click(object sender,EventArgs e)//在选择一行后单击编辑
{
pnlExternalForm.Visible = true;
RadGrid Grid =(this.FindControl("RadGrid1")as RadGrid);
字符串Pid = Convert.ToString(Grid.SelectedValues ["Pid"]);
字符串查询="SELECT * FROM tblProducts其中Pid ="''+ Pid +''";
GetProductInfoForEdit(query,Pid);
BindGrid();
}

私有void GetProductInfoForEdit(字符串查询,字符串ProductId)
{
DataSet ds = objSQLHelper.GetInventoryForm(query);
txtItemNamePanel.Text = Convert.ToString(ds.Tables [0] .Rows [0] ["ProductName"]);
txtQtyAvailablePanel.Text = Convert.ToString(ds.Tables [0] .Rows [0] ["QtyAvailable"]);
txtRatePanel.Text = Convert.ToString(ds.Tables [0] .Rows [0] ["Rate"]);
lblIdPanel.Text = ProductId;
BindGrid();
}
在文本框中编辑值之后,面板上的受保护的无效btnSaveChanges_Click(object sender,EventArgs e)//保存在面板上的按钮
{
如果(!string.IsNullOrEmpty(lblIdPanel.Text))
{
UpdateProductInfo();
BindGrid();
}
}

私有void UpdateProductInfo()
{
试试
{
int结果= objSQLHelper.UpdateRowsInDb(Convert.ToInt32(lblIdPanel.Text),Convert.ToString(txtItemNamePanel.Text),Convert.ToInt32(txtQtyAvailablePanel.Text),Convert.ToInt32(txtRatePanel.Text));
BindGrid();//这里我在更新后重新绑定了
HidePanel();
}
catch(ex ex例外)
{

}
}

私有void HidePanel()
{
txtItemNamePanel.Text =";
txtQtyAvailablePanel.Text =";
txtRatePanel.Text =";
lblIdPanel.Text =";
pnlExternalForm.Visible = false;
}

谢谢
Amit.

Hey there,

I am using a RadGrid in which i am using a dataset as datasource and bringing complete database table on the grid.I am using Buttond for Edit,Delete and Save outside the grid on Row Select.I have made an asp:Panel under the grid to show the textBoxes for editing values for the selected row.Now my asp:panel contains 2 buttons save and cancel.

My problem is:--
The values of the selected rows are shown in the textBoxes on panel for editing,And after editing when i click save I''ve hided the panel but values are not saved in the row.Unless postback takes place,like if i select another row and click edit then page postbacks and the row edited previously now shows the edited values in the gridRow.

I am not using Need Data Suorces event of Grid.Is it mandatory to use?
If so whats the proper method of implementing it in my case?

This is my code--

protected void SaveChanges_Click(object sender, EventArgs e)//On edit click after selecting a row
{
pnlExternalForm.Visible = true;
RadGrid Grid = (this.FindControl("RadGrid1") as RadGrid);
string Pid = Convert.ToString(Grid.SelectedValues["Pid"]);
string query = "SELECT * FROM tblProducts where Pid=''" + Pid + "''";
GetProductInfoForEdit(query, Pid);
BindGrid();
}

private void GetProductInfoForEdit(string query, string ProductId)
{
DataSet ds = objSQLHelper.GetInventoryForm(query);
txtItemNamePanel.Text = Convert.ToString(ds.Tables[0].Rows[0]["ProductName"]);
txtQtyAvailablePanel.Text = Convert.ToString(ds.Tables[0].Rows[0]["QtyAvailable"]);
txtRatePanel.Text = Convert.ToString(ds.Tables[0].Rows[0]["Rate"]);
lblIdPanel.Text = ProductId;
BindGrid();
}
protected void btnSaveChanges_Click(object sender, EventArgs e)//Save button on panel after editing values in the text boxes
{
if (!string.IsNullOrEmpty(lblIdPanel.Text))
{
UpdateProductInfo();
BindGrid();
}
}

private void UpdateProductInfo()
{
try
{
int result = objSQLHelper.UpdateRowsInDb(Convert.ToInt32(lblIdPanel.Text), Convert.ToString(txtItemNamePanel.Text), Convert.ToInt32(txtQtyAvailablePanel.Text), Convert.ToInt32(txtRatePanel.Text));
BindGrid();//Here i have rebinded after Update
HidePanel();
}
catch (Exception ex)
{

}
}

private void HidePanel()
{
txtItemNamePanel.Text = "";
txtQtyAvailablePanel.Text = "";
txtRatePanel.Text = "";
lblIdPanel.Text = "";
pnlExternalForm.Visible = false;
}

Thanks
Amit.

推荐答案

好吧,要么使用XMLHttpRequest在服务器端维护更改,要么在关闭面板后提交更改.

我不确定,但是如果您的Radgrid支持一次编辑行数并在以后提交,那么您也可以尝试这样做.
Well, either using XMLHttpRequest maintain the changes on server side OR commit the changes once panel is closed.

I am not sure, but if your Radgrid supports editing number of rows at once and commit later than you can try that too.


这篇关于Rad网格编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆