2013-12-14 20 views
0

我.cs文件JavaScript函數的<asp:Buttoncolumn>

protected void Page_Load(object sender, EventArgs e) 
    { 
     string arg = Request.Form["__EVENTTARGET"]; 
     string val= Request.Form["EVENTARGUMENT"]; 


     if (arg == "Delete") 
     { 
      DeleteRecord(); 

     } 
     if (!IsPostBack) 
      { 

      PopulateDelete(); 
     } 


    } 

和我的aspx頁面Javascript方法是

<script language="javascript"> 
    function Confirm() { 
     var fRet; 

     fRet = confirm('Do you want to Delete the record?'); 
     if (fRet == true) 
      __doPostBack('Delete', fRet); 
     return true; 
    } 

的GridView在aspx頁面是

<asp:DataGrid ID="dgProducts" runat="server" AutoGenerateColumns="False"   BackColor="#DEBA84" 
     BorderColor="#DEBA84" BorderWidth="1px" CellPadding="3" 
     BorderStyle="None" CellSpacing="2" 
     CssClass="HCStyle" ondeletecommand="dgProducts_DeleteCommand" > 
     <Columns> 
      <asp:BoundColumn DataField="SerialNo" HeaderText="SerialNo"> 
       <ItemStyle HorizontalAlign="Left" Wrap="False"></ItemStyle> 
      </asp:BoundColumn> 

      <asp:BoundColumn DataField="Organization" HeaderText="Organization"> 
       <ItemStyle HorizontalAlign="Left" Wrap="False"></ItemStyle> 
      </asp:BoundColumn> 

      <asp:BoundColumn DataField="Origin" HeaderText="Origin"> 
      <ItemStyle HorizontalAlign="Left" Wrap="false" /> 
      </asp:BoundColumn> 

      <asp:BoundColumn DataField="Service" HeaderText="Services"> 
      <ItemStyle HorizontalAlign="Left" Wrap="false" /> 
      </asp:BoundColumn> 

      <asp:BoundColumn DataField="Location" HeaderText="Location"> 
      <ItemStyle HorizontalAlign="Left" Wrap="false" /> 
      </asp:BoundColumn> 

      <asp:BoundColumn DataField="Established" HeaderText="Established"> 
      <ItemStyle HorizontalAlign="Left" Wrap="false" /> 
      </asp:BoundColumn> 
      <asp:ButtonColumn CommandName="Delete" HeaderText="Delete" Text="Delete"> 
       <ItemStyle HorizontalAlign="Left" /> 
      </asp:ButtonColumn> 

根據當我點擊GridView中的刪除按鈕時,這將會顯示一個JavaScript文本框,如果我點擊是在JS文本框然後刪除應該調用teRecord()方法,但我得到的參數值爲「dgProducts $ ctl02 $ ctl00」,,我怎樣才能調用DeleteRecords()方法... plz help meeeeeeeeee

回答

-1

添加一個類來ButtonColumn
<asp:ButtonColumn CommandName="Delete" HeaderText="Delete" Text="Delete" ControlStyle-CssClass="deleteButton" ><ItemStyle HorizontalAlign="Left" /></asp:ButtonColumn>
更改JavaScript函數如下

$(document).ready(function() {
$('.deleteButton').click(function() { return confirm('Do you want to Delete the record?'); }); });

+1

ButtonColumn不有一個名爲 「ControlStyle-的CssClass」 –

+0

HTTP屬性:// stackoverflow.com/questions/5351064/how-to-set-cssclass-on-button-in-datagrid – Kamlesh