Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a gridview and i want to send sms to user on button click event and save some data into database (i am using sql server) . But my problem is that when first row complete update in gridviw show status sent(in UI) while process will be continue

my gridView


XML
<asp:GridView ID="grdvdiffrentMsg" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="Mobile No">
<ItemTemplate>
    <asp:Label ID="lblMobileNo" runat="server" Text='<%# Eval("mobileNo") %>' />
    <asp:HiddenField ID="hfStudId" runat="server" Value='<%# Eval("StudId") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Meassage">
<ItemTemplate>
    <asp:Label ID="lblMessage" runat="server" Text='<%# Eval("Message") %>'></asp:Label>
    </ItemTemplate>
</asp:TemplateField>

</Columns>
    </asp:GridView>
    <p>
        <asp:Button ID="btnSendMsg" runat="server" Text="Send"
            onclick="btnSendMsg_Click" />
    </p>



my button click event

sendSMS

C#
protected void btnSendMsg_Click(object sender, EventArgs e)
{
    int sms=0;
    if (Session["SMS"] != null)
    {
        sms = Convert.ToInt32(Session["SMS"].ToString());
    }
    if (sms > 0)
    {
    //foreach (GridViewRow gvr in grdvdiffrentMsg.Rows)
    // {
    //     HiddenField stuId = (HiddenField)gvr.FindControl("hfStudId");
    //     Label lblMobileNo = (Label)gvr.FindControl("lblMobileNo");
    //     Label lblMsg = (Label)gvr.FindControl("lblMessage");
         //if (lblMobileNo.Text != string.Empty && lblMsg.Text != string.Empty)
         //{
            dt=(DataTable)ViewState["MultiSMS"];
             objcommonsms.sendSMS(ddlMsgType.SelectedItem.Text, Session["SenderId"].ToString(),Session["UserId"].ToString(),sms,dt);
         //}

     //}
    }

}


sendSMS function is used for save data in database


please show me code with example


thanks in advance
Posted
Updated 9-May-13 1:55am
v2
Comments
pradiprenushe 14-Aug-13 4:20am    
This cant be done in single call. You can use hidden button in each row with some command name.
Through javascript call each row button click asynchrounously.
pradiprenushe 14-Aug-13 4:22am    
You have to
No of sms send = no of calls to server (asynchronously)
Use Page method to call server side functionality

Do following steps
1.loop through gridview
http://patelpc.blogspot.in/2011/12/loop-through-gridview-row-in-javascript.html
2. Use page method for send mail
http://aspsnippets.com/Articles/Call-ASPNet-Page-Method-using-jQuery-AJAX-Example.aspx

1 solution

i've used it here is the code use it as per your requirement

C#
protected void Button1_Click(object sender, EventArgs e)
    {

       
for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            TextBox tb1 = GridView1.Rows["row index"].FindControl("Textbox1") as TextBox;
            UpdateFunction(tb1.Text);
        }

}
 
Share this answer
 
Comments
ashok luhach 9-May-13 23:01pm    
UpdateFunction(tb1.Text) sir how this function update gridview column
Bikash Prakash Dash 10-May-13 0:43am    
My friend this is a sample function i'm giving example, use your function for update instead of this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900