2014年6月9日 星期一

ASP.NET Gridview Edit 按兩次才能編輯解決方法

ASP.NET Gridview Edit 按兩次才能編輯解決方法

C#:
  1. protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
  2. {
  3. try
  4. {
  5. //1.重新綁定
  6. GridView1.EditIndex = e.NewEditIndex;
  7. //2.重新DataBind
  8. Gvlistitem.DataSource = dt;
  9. GridView1.DataBind();
  10. }
  11. catch (Exception)
  12. {
  13. throw;
  14. }
  15. }

2014年6月4日 星期三

ASP.NET Foreach RadioButton

ASP.NET Foreach RadioButton



HTML:
  1. <asp:Panel ID="pan_RadioButton1" runat="server">
  2. <asp:RadioButton ID="rbtempty" runat="server" GroupName="ProjectType" Text="Empty project without any defaults." /><br />
  3. <asp:RadioButton ID="rbtcopy" runat="server" GroupName="ProjectType" Text="Copy an existing project." />&nbsp;
  4. <asp:DropDownList ID="ddlcopymodel" runat="server" Width="100"></asp:DropDownList>
  5. </asp:Panel>
  6. <asp:Button ID="btnSave" runat="server" Text="Save" Width="100" OnClientClick="return confirm('Do you really want to save?');" OnClick="btnSave_Click" />
  7. <asp:Button ID="btnprojecttypecancel" runat="server" Text="Cancel" Width="100" />

C#:
  1. protected void btnSave_Click(object sender, EventArgs e)
  2. {
  3. try
  4. {
  5. string r_id = "";
  6. string r_value = "";
  7. foreach (Control ctrl in pan_RadioButton1.Controls)//pan_RadioButton1這是Panel物件,取出Panel中所有物件
  8. {
  9. if (ctrl.GetType().Name == "RadioButton") //判斷物件是否為RadioButton
  10. {
  11. RadioButton rbt = ctrl as RadioButton; //將ctrl建立成RadioButton物件
  12. if (rbt.Checked) //判斷RadioButton是否被選取
  13. {
  14. r_id = rbt.ID.ToString();
  15. r_value = rbt.Text;
  16. }
  17. }
  18. }
  19. }
  20. catch (Exception)
  21. {
  22. throw;
  23. }
  24. }