0

I have One gridview which looks like below enter image description here

This is Grdiview & On click of this Reject Button one pop up is enabled Using Css. like below image

enter image description here

On this SAVE CHAGNES button I need ID of reject button' Row from gridview.

So I am thinking about query string. but dont know how to achieve that.

Here is my HTML

<Columns>



    <asp:TemplateField HeaderText="REject Button">
        <ItemTemplate>

            <asp:LinkButton ID="lnkReject" href="#add-post-titl" data-toggle="modal" CommandName="status_reject_cmd" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "purchase_order_no")%>' runat="server" Text='<i class="fa fa-thumbs-o-down"></i>&nbsp;Reject'></asp:LinkButton>
        </ItemTemplate>
    </asp:TemplateField>


</Columns>
<PagerStyle CssClass="paging" HorizontalAlign="Right" Font-Underline="false" />
<AlternatingRowStyle CssClass="gvstyling_alternate" />

<div aria-hidden="true" role="dialog" tabindex="-1" class="modal fade" id="add-post-titl" style="display: none;">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header blue">
                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                <h4 class="modal-title">Reject Information</h4>
            </div>


                <div class="modal-body">
                    <asp:DropDownList Width="100%" heig="15%" ID="ddlReject_Type" runat="server">
                        <%-- <asp:ListItem Text="Select Reject Type" Value="0"></asp:ListItem>
                        <asp:ListItem Text="Select Reject Type" Value="0"></asp:ListItem>
                        <asp:ListItem Text="Select Reject Type" Value="0"></asp:ListItem>--%>
                    </asp:DropDownList>

                    <%--<input type="text" placeholder="TITLE" />--%>
                    <textarea placeholder="DESCRIPTION" rows="5"></textarea>
                </div>
                <div class="modal-footer">
                    <button data-dismiss="modal" class="btn btn-default black" type="button">Close</button>
                    <asp:Button ID="btn_Reject" OnClick="btn_Reject_Click" CssClass="btn btn-primary blue" runat="server" Text="Save changes" />
                    <%--<button class="btn btn-primary blue" type="button">Save changes</button>--%>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
    </div> 

Here is the button click on which I want ID of reject button

protected void btn_Reject_Click(object sender, EventArgs e)
    {

        string updatePO_Master = "update RS_Purchase_Order_Master set rejected = '1' where purchase_order_no = '" + ID + "'";
        cm.TableInsert(updatePO_Master);
        FillPurchaseOrder();        
    }
Hardik Parmar
  • 1,053
  • 3
  • 15
  • 39
  • You can't use an id more than once per page, and you put it in an item template which means every item will have an element with the same id. Asp.net changes these duplicate ids. As to your question, what did you have trouble with? – Moti Azu Nov 17 '14 at 08:42
  • Like in Asp if we redirect on page from another we get Query string to redirect but how with the jquery I can do the same – Hardik Parmar Nov 17 '14 at 08:45
  • http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript – Moti Azu Nov 17 '14 at 08:47

2 Answers2

0

IMHO, you can use a hidden field to store the ID. You can implement the setting of ID from RowCommand of your gridview. Please see example below

    if (e.CommandName == "Reject")
    {
        int index = Convert.ToInt32(e.CommandArgument.ToString());
        //data keys
        string ID = (string)this.gv.DataKeys[index]["myKey"];
        //hidden field or label
        Label ID = (Label)this.gv.Rows[index].FindControl("");

        HiddenField_ID.Text = ID.Text;
    }

From there you have now the access to the ID and you can pass it to the Save Changes Button.

protected void btn_Reject_Click(object sender, EventArgs e)
    {

        string updatePO_Master = "update RS_Purchase_Order_Master set rejected = '1' where purchase_order_no = '" + HiddenField_ID.Text + "'";
        cm.TableInsert(updatePO_Master);
        FillPurchaseOrder();        
    }

As you mentioned in the comment, you're using a client side.

In the columns tag of your GridView, add an additional element like an hidden field and bind it with your ID

 <asp:TemplateField HeaderText="REject Button">
        <ItemTemplate>
            <asp:HiddenField runat="server" ID="purchaseid" Value='<%# Eval("purchase_order_no") %>' />
            <asp:LinkButton ID="lnkReject" href="#add-post-titl" data-toggle="modal" CommandName="status_reject_cmd" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "purchase_order_no")%>' runat="server" Text='<i class="fa fa-thumbs-o-down"></i>&nbsp;Reject'></asp:LinkButton>
        </ItemTemplate>
    </asp:TemplateField>
Chris
  • 599
  • 7
  • 23
  • Hey Button this is totally client Side control will not go to server side – Hardik Parmar Nov 17 '14 at 09:13
  • Assumed that your gridview has hiddenfield which is the ID... //Unique Key of the row `var ID = $('input[id*=rejectbtn]).closest('tr').find(.classID).text();` – Chris Nov 17 '14 at 09:43
0

Get the row id based on the Reject button on click and store it on a hidden filed. On SAVE CHAGNES button click, get the value from the hidden field.

Alakesh
  • 1
  • 2
  • I already told that this is gonna execute on client side not on server side – Hardik Parmar Nov 17 '14 at 09:38
  • That was suggested to be done on client side using JQuery only. $( "#lnkReject" ).on( "click", function() { // get the row ID here set to a hidden field }); – Alakesh Nov 17 '14 at 09:41