Note that there are some explanatory texts on larger screens.

plurals
  1. POCount of likes for image
    primarykey
    data
    text
    <p>i am creating an image gallery (images stored in Images folder,path saved in db) in the gridview</p> <p>Each imagename is saved in dbwith and uinque id and the columnname : storyid.</p> <p>can anyone tell me how to bind the indiviudal images "like" count in the lblcount</p> <pre><code>&lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;asp:ScriptManager runat="server" ID="SM1"&gt; &lt;/asp:ScriptManager&gt; &lt;div&gt; &lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Font-Names="Arial" OnRowCommand="GridView1_RowCommand1"&gt; &lt;Columns&gt; &lt;asp:TemplateField&gt; &lt;ItemTemplate&gt; &lt;asp:UpdatePanel runat="server" ID="up1" UpdateMode="Conditional"&gt; &lt;ContentTemplate&gt; &lt;asp:Button runat="server" ID="IncreaseButton" Text="Like" CommandName="Increase" CommandArgument="&lt;%# ((GridViewRow) Container).RowIndex %&gt;" /&gt; &lt;asp:Label runat="server" ID="lblCount"&gt;&lt;/asp:Label&gt; &lt;div style="display: none;"&gt; &lt;asp:Label Text="&lt;%#Bind('StoryId')%&gt;" ID="lblStoryid" runat="server"&gt;&lt;/asp:Label&gt; &lt;/div&gt; &lt;/ContentTemplate&gt; &lt;/asp:UpdatePanel&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:ImageField DataImageUrlField="FilePath" ControlStyle-Width="100" ControlStyle-Height="100" HeaderText="Preview Image"&gt; &lt;ControlStyle Height="100px" Width="100px"&gt;&lt;/ControlStyle&gt; &lt;/asp:ImageField&gt; &lt;asp:TemplateField&gt; &lt;HeaderTemplate&gt; &lt;asp:Label Text="Description" runat="server" Visible="False"&gt;&lt;/asp:Label&gt; &lt;/HeaderTemplate&gt; &lt;ItemTemplate&gt; &lt;asp:Label Text="&lt;%#Bind('Description')%&gt;" ID="lblImageid" runat="server"&gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;EditItemTemplate&gt; &lt;/EditItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; &lt;/div&gt; &lt;/form&gt; </code></pre> <p></p> <pre><code>public partial class Gallery : System.Web.UI.Page </code></pre> <p>{</p> <pre><code>private void bindimage() { DataTable dt = new DataTable(); String strConnString = System.Configuration.ConfigurationManager. ConnectionStrings["dbconnection"].ConnectionString; string strQuery = "select * from story"; SqlCommand cmd = new SqlCommand(strQuery); SqlConnection con = new SqlConnection(strConnString); SqlDataAdapter sda = new SqlDataAdapter(); cmd.CommandType = CommandType.Text; cmd.Connection = con; try { con.Open(); sda.SelectCommand = cmd; sda.Fill(dt); GridView1.DataSource = dt; GridView1.DataBind(); } catch (Exception ex) { Response.Write(ex.Message); } finally { con.Close(); sda.Dispose(); con.Dispose(); } } protected void GridView1_RowCommand1(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Increase") { int index = Convert.ToInt32(e.CommandArgument); GridViewRow row = GridView1.Rows[index]; Label listPriceTextBox = (Label)row.FindControl("lblStoryid"); int storyId = Convert.ToInt32(listPriceTextBox.Text); string UserEmailid = "aditya.arjula@gmail.com"; String strConnString = System.Configuration.ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString; SqlConnection con = new SqlConnection(strConnString); string strQuery = "INSERT INTO Likes(storyId,UserEmailid) VALUES(@storyId,@UserEmailid)"; string LikeCount = "SELECT COUNT(StoryId) FROM Likes Where StoryId=1001;;"; Label lblStoryid = (Label)row.FindControl("lblStoryid"); lblStoryid.Text = LikeCount; SqlCommand cmd = new SqlCommand(strQuery); SqlCommand cmdl = new SqlCommand(LikeCount); cmdl.CommandType = CommandType.Text; cmdl.Connection = con; cmd.Parameters.AddWithValue("@storyId", storyId); cmd.Parameters.AddWithValue("@UserEmailid", UserEmailid); cmd.CommandType = CommandType.Text; cmd.Connection = con; try { con.Open(); cmd.ExecuteNonQuery(); cmdl.ExecuteNonQuery(); } catch (Exception ex) { Response.Write(ex.Message); } finally { con.Close(); con.Dispose(); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload