|
5#
楼主 |
发表于 2013-7-19 08:44:11
|
只看该作者
- <P>页面代码:</P>
- <P><x:PageManager ID="PageManager1" runat="server" />
- <x:Grid ID="Grid1" ShowBorder="true" ShowHeader="true" Title="课程管理" Width="800px" Height="465px"
- runat="server" DataKeyNames="c_Id" AllowCellEditing="true" EnableColumnLines="true" ClicksToEdit="2" EnableRowNumber="True" OnRowCommand="Grid1_RowCommand" AllowPaging="True" OnPageIndexChange="Grid1_PageIndexChange" PageSize="15">
- <Toolbars>
- <x:Toolbar ID="Toolbar1" runat="server" >
- <Items>
- <x:Button ID="btnNew" Text="新增数据" Icon="Add" EnablePostBack="false" runat="server">
- </x:Button>
- <x:ToolbarFill ID="ToolbarFill1" runat="server">
- </x:ToolbarFill>
- </Items>
- </x:Toolbar>
- </Toolbars>
- <Columns>
- <x:RenderField ColumnID="course_Name" Width="200px" DataField="course_Name" FieldType="String"
- HeaderText="课 程">
- <Editor>
- <x:TextBox ID="tbxEditorName" Required="true" runat="server">
- </x:TextBox>
- </Editor>
- </x:RenderField>
- <x:RenderField ExpandUnusedSpace="true" ColumnID="course_Desc" DataField="course_Desc" FieldType="String"
- HeaderText="课程备注">
- <Editor>
- <x:TextBox ID="tbxEditorDesc" runat="server">
- </x:TextBox>
- </Editor>
- </x:RenderField>
-
- <x:LinkButtonField HeaderText="删 除" Width="50px" ConfirmText="你确定要这么做么?"
- CommandName="Delete" Icon="Delete" ConfirmTarget="Parent" />
-
- </Columns>
- </x:Grid>
- <br />
- <x:Button runat="server" ID="btnSave" Text="保存数据" OnClick="btnSave_click"></x:Button></P>
- <P> </P>
- <P>后台代码:</P>
- <P>public partial class admin_a_CourseManage : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
-
- if (!IsPostBack)
- {
- InitInsert();
- BindGrid();
- }
-
- }
-
- private void BindGrid()
- {
- DataTable table = DALCourse.dtList();</P>
- <P> Grid1.DataSource = table;
- Grid1.DataBind();
- }
-
- //点击新增一条显示数据
- private void InitInsert()
- {
- JObject defaultObj = new JObject();
- defaultObj.Add("course_Name", "请输入课程名称");
- defaultObj.Add("course_Desc", "描述");
- // 第一行新增一条数据
- btnNew.OnClientClick = Grid1.GetAddNewRecordReference(defaultObj,false);
- }</P>
- <P> //数据保存
- protected void btnSave_click(object sender, EventArgs e)
- {
-
- Dictionary<int, Dictionary<string, string>> modifiedDict = Grid1.GetModifiedDict();
- for (int i = 0, count = Grid1.Rows.Count; i < count; i++)
- {
- if (modifiedDict.ContainsKey(i))
- {
-
- Dictionary<string, string> rowDict = modifiedDict[i];
- string id = Grid1.Rows[i].DataKeys[0].ToString();
- string courseName = "", courseDesc = "";
- if (rowDict.ContainsKey("course_Name"))
- {
- courseName = rowDict["course_Name"];
- }
- else
- {
- courseName = Grid1.Rows[i].Values[0];
- }
- if (rowDict.ContainsKey("course_Desc"))
- {
- courseDesc = rowDict["course_Desc"];
- }
- else
- {
- courseDesc = Grid1.Rows[i].Values[1];
- }
- DALCourse.update(courseName, courseDesc, id);
- }
- }</P>
- <P> // 2. 再新增数据
- List<Dictionary<string, string>> newAddedList = Grid1.GetNewAddedList();
- for (int i = newAddedList.Count - 1; i >= 0; i--)
- {
-
- DALCourse.Insert(newAddedList[i]["course_Name"], newAddedList[i]["course_Desc"]);
- }
- BindGrid();
-
- Alert.Show("数据保存成功");
-
- }</P>
- <P> //行命令--删除
- protected void Grid1_RowCommand(object sender, FineUI.GridCommandEventArgs e)
- {
- if (e.CommandName == "Delete")
- {
- string id = Grid1.Rows[e.RowIndex].DataKeys[0].ToString();
- DALCourse.Delete(id);
- BindGrid();
- Alert.ShowInParent("删除数据成功!");
- }
- }</P>
- <P> //分页
- protected void Grid1_PageIndexChange(object sender, FineUI.GridPageEventArgs e)
- {
- Grid1.PageIndex = e.NewPageIndex;
- }</P>
- <P>}</P>
- <P> </P>
- <P>DALCourse类 中的更新代码(update 方法):</P>
- <P>/// <summary>
- /// 更新一条数据
- /// </summary>
- /// <param name="courseName">课程名称</param>
- /// <param name="courseDesc">课程描述</param>
- /// <param name="id"></param>
- public static void update(string courseName, string courseDesc,object id)
- {
- string sql = "update t_course set <A href="mailto:course_Name=@courseName,course_Desc=@courseDesc">course_Name=@courseName,course_Desc=@courseDesc</A> where <A href="mailto:c_Id=@id">c_Id=@id</A>";
- SqlParameter[] paras = new SqlParameter[] {
- new SqlParameter("@courseName", courseName),
- new SqlParameter("@courseDesc", courseDesc) ,
- new SqlParameter("@id", id)
- };
- helper.Exexute(sql, paras);
- }</P>
- <P> </P>
- <P> </P>
- <P> </P>
- <P> </P>
- <P> </P>
复制代码 问题:::代码执行完全没有问题,新增一行数据点击保存也没有问题,但是修改一行数据,再保存,能执行方法,已经更新回数据库了,但是页面没更新,如果方法的参数改成具体值,那也没有问题
|
|