views:

29

answers:

0

Hi

I am adding some rows to the gridview using javascript

Now I have a image as 1 of the columns and I can succefully place the image thorugh javascript

I have written a row_command event on the server side for image click

This does and fetch something from database

My question is how do add click event to image when I add rows through javascript so that it call row_command event on server side

This is my gridview

<asp:GridView ID="XGrid1"  runat="server"    
 AutoGenerateColumns="true" CellPadding="2" Width="90%"  
 OnRowCommand="XGrid1_RowCommand" >   
      <HeaderStyle CssClass="tblHeader" />   
      <Columns>   
          <asp:BoundField DataField="RowSerialId" HeaderText="Id"  />       
          <asp:TemplateField>                 
              <ItemTemplate>   
                  <asp:ImageButton ID="imgbtnShow" Width="0.5pc" runat="server"
                   ImageUrl="~/Images/sysImages/Action_Add.gif"
                   AlternateText="Show" CommandName="Show"  />   
              </ItemTemplate>   
              <ItemStyle VerticalAlign="Top"  Width="50px"  />   
          </asp:TemplateField>   
      </Columns>   
</asp:GridView>

I am using this code which gets called from jQuery code on aspx page

private string BuildRowsWithImageButton(DataTable dt, Int32 aLastRowId) {   
   StringBuilder sb = new StringBuilder();
   System.Data.DataRow dr;
   int jId = 0;
   if (dt.Rows.Count > 0) {
      for (int i = 0; i < dt.Rows.Count; i++) {
         sb.Append("<tr class='View_RowStyle'>");
         //sb.Append("<td><input type='image' name=" + strImgName + 
           " id='ctl00_ContentPlaceHolder1_XGrid1_ctl05_imgbtnShow' " +
           "runat='server' src='../../Images/sysImages/Action_Add.gif' " +
           "alt='Show' style='width:0.5pc;border-width:0px;' " +
           "onclick=" + strPostBack + "  /></td>");
         dr = dt.Rows[i];
         jId = aLastRowId + i;
         string strImgName = "ctl00$ContentPlaceHolder1$XGrid1$ctl" 
           + jId + "$imgbtnShow";
         //string strImgName = "ctl00_ContentPlaceHolder1_UpdatePanel1";
         string strImgId = "ctl00_ContentPlaceHolder1_XGrid1_ctl" 
           + jId + "_imgbtnShow";

         sb.Append("<td><input type='image'  name=" + strImgName + 
           " id='ctl00_ContentPlaceHolder1_XGrid1_ctl05_imgbtnShow' " +
           "runat='server' src='../../Images/sysImages/Action_Add.gif' " +
           "alt='Show' style='width:0.5pc;border-width:0px;' " +
           "CommandName='Show' /></td>");

         for (int j = 0; j < dt.Columns.Count; j++) {
            sb.Append("<td>" + dr[j] + "</td>");
         }
         sb.Append("</tr>");
        }
    }
    return sb.ToString();
}