2016-08-26 4 views
0

Вот код, когда я пытаюсь сгореть случай в браузере он не стрелялИзображение кнопки OnClick событие не стрельбы

 <asp:Panel ID="StateDistrictGrid_pnl" runat="server"> 
 
     <asp:GridView ID="User_grd" runat="server" DataKeyNames="VoterID" AutoGenerateColumns="False" AllowPaging="True"> 
 
      <Columns> 
 
       <asp:TemplateField HeaderText="Edit"> 
 
        <ItemTemplate> 
 
         <asp:ImageButton ID="Img_btn" ImageUrl="~/Images/52105-200.png" OnClick="Img_btn_Click" Height="20px" Width="30px" runat="server" /> 
 
        </ItemTemplate> 
 
       </asp:TemplateField> 
 
       <asp:BoundField DataField="ID" Visible="false" /> 
 
       <asp:BoundField DataField="VoterName" HeaderText="Voter Name" SortExpression="VoterName" /> 
 
       <asp:BoundField DataField="StateName" HeaderText="State Name" SortExpression="StateName" /> 
 
       <asp:BoundField DataField="DistrictName" HeaderText="District Name" SortExpression="DistrictName" /> 
 
      </Columns> 
 
     </asp:GridView> 
 
     <asp:Label ID="Lbl_Result" runat="server"> 
 
      <asp:Button ID="BtnShowPopup" runat="server" Text="Edit" /> 
 
      <asp:ModalPopupExtender ID="Show_mpe" runat="server" TargetControlID="BtnShowPopup" PopupControlID="PopUp_Pnl" CancelControlID="Btn_Cancel" BackgroundCssClass="textbox_radius"></asp:ModalPopupExtender> 
 
      <asp:Panel ID="PopUp_Pnl" runat="server" style = "display:none"> 
 
<asp:Label Font-Bold = "true" ID = "Details_lbl" runat = "server" Text = "Voter Details" ></asp:Label> 
 
<br /> 
 
<table align = "center"> 
 
     <tr> 
 
<td> 
 
<asp:Label ID = "ID_lbl" runat = "server" Text = "Voter ID" ></asp:Label> 
 
</td> 
 
<td> 
 
<asp:TextBox ID="VoterID_txt" runat="server"></asp:TextBox> 
 
</td> 
 
</tr> 
 
    <tr> 
 
<td> 
 
<asp:Label ID = "Voter_lbl" runat = "server" Text = "Voter Name" ></asp:Label> 
 
</td> 
 
<td> 
 
<asp:TextBox ID="VoterName_txt" runat="server"></asp:TextBox> 
 
</td> 
 
</tr> 
 
<tr> 
 
<td> 
 
<asp:Label ID = "Statepnl_lbl" runat = "server" Text = "State Name" ></asp:Label> 
 
</td> 
 
<td> 
 
<asp:TextBox ID="State_txt" runat="server"></asp:TextBox> 
 
</td> 
 
</tr> 
 
    <tr> 
 
<td> 
 
<asp:Label ID = "Districtpnl_lbl" runat = "server" Text = "District Name" ></asp:Label> 
 
</td> 
 
<td> 
 
<asp:TextBox ID="District_txt" runat="server"></asp:TextBox> 
 
</td> 
 
</tr> 
 
<tr> 
 
<td> 
 
<asp:Button ID="btnSave" runat="server" Text="Save" /> 
 
</td> 
 
<td> 
 
<asp:Button ID="Btn_Cancel" runat="server" Text="Cancel" /> 
 
</td> 
 
</tr> 
 
</table> 
 
</asp:Panel> 
 
     </asp:Label> 
 

 
     </asp:Panel>

и код Бэкэнд так: является тир любой проблемы в в моем коде, пожалуйста, помогите спасибо

protected void Img_btn_Click(object sender, ImageClickEventArgs e) 
{ 
    ImageButton Bt = sender as ImageButton; 
    GridViewRow GVRow = (GridViewRow)Bt.NamingContainer; 
    ID_lbl.Text = User_grd.DataKeys[GVRow.RowIndex].Value.ToString(); 
    VoterName_txt.Text = GVRow.Cells[2].Text; 
    State_txt.Text = GVRow.Cells[3].Text; 
    District_txt.Text = GVRow.Cells[4].Text; 
} 

, но когда я запускаю это событие не Fired..What проблемы?

+0

попробуйте поставить 'alert' и проверить ... – BNN

+0

Вы не можете использовать обычное событие OnClick на кнопке внутри шаблона GridView. Вам нужно подписаться на событие OnRowCommand вашего GridView. Вы даете своему ImageButton уникальное имя CommandName и проверяете это имя в событии RowCommand. Посмотрите, как это сделать здесь http://www.codeproject.com/Tips/564619/Example-of-gridview-rowcommand-on-Button-Click – Scotty

+0

Вы разместили свой код внутри панели обновления? –

ответ

0
Your issue is somehow same....that i encountered few months back... look at this one ...this might help you some way or another... try using LINKBUTTON instead of BUTTON... 

<asp:gridview runat="server" id="GridView1" showfooter="true" 
    autogeneratecolumns="false" GridLines="None" CssClass="table1" 

    OnRowCreated="GridView1_RowCreated" BorderColor="#356600" 
    BorderStyle="Solid" > 
    <columns> 
<asp:TemplateField HeaderText="Date" > 
<ItemTemplate> 

<asp:LinkButton ID="Date" runat="server" CausesValidation="false" CommandName="Date_Select" Text='<%#Eval("Date","{0:yyyy-MM-dd}") %>' onclick="Date_Click" EnableTheming="False"></asp:LinkButton> 

</ItemTemplate> 
<EditItemTemplate> 
</EditItemTemplate> 
</asp:TemplateField> 

<asp:boundfield datafield="Profit" headertext="Profit" 
      footerstyle-font-bold="true"> 
<FooterStyle Font-Bold="True"></FooterStyle> 
     </asp:boundfield> 

    </columns> 

protected void Date_Click(object sender, EventArgs e) 
{ 

     LinkButton Lnk = (LinkButton)sender; 

     Label1.Text = Lnk.Text; // This one works for me.... 

      OdbcConnection con1 = new OdbcConnection(ConfigurationManager.ConnectionStrings["connect1"].ConnectionString); 
      OdbcCommand cmd = new OdbcCommand("select a.customer As Customer,a.mins as MIns,a.amount as Amount,a.profit as Profit from summarydatashort a,clientsrecord b where a.orig_clli=b.orig_clli and a.date='" + Label1.Text + "' and b.emplye='Ankit'", con1); 
     con1.Open(); 
     OdbcDataAdapter da = new OdbcDataAdapter(cmd); 
     da.Fill(ds); 

     con1.Close(); 
     GridView17.DataSource = ds; 
     GridView17.DataBind(); 


    } 
Смежные вопросы