Home  »  Forum  »  ASP.Net  »

Gridview using linkbutton and href link dynamic or visible another on hide how?

 Posted By : chandru MPosted Date : 19/07/2011 04:05:55 PM Category : ASP.Net Points : 1

Dear all,

am using two type of uploading one file uploadcontrol(linkbutton download for upload files) another one href link in post both are saved in database. but one time upload for any one file only. another file hide how..
am code:
if (fileVideofile.HasFile)
{
//Save File to the proper directory
string filename = Path.GetFileName(fileVideofile.FileName);
fileVideofile.SaveAs(Server.MapPath("UploadFiles/") + filename);
Videofile = "UploadFiles/" + fileVideofile.FileName;
es/") + fileVideofile.FileName);

}
else
{
Videofile = "empty.wav";
fileVideofile.SaveAs(Server.MapPath("UploadFiles/") + Videofile);
cmd.Parameters.AddWithValue("@Uploadimages",Videofile);
cmd.Parameters.AddWithValue("@Url", txtUrl.Text);
<asp:GridView ID="GridVideofile" runat="server" AutoGenerateColumns="false" Width="647px"
CssClass="GV" onrowdatabound="GridVideofile_RowDataBound"
ShowHeader="False">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<tr>
<td>
Download Video File :
<asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click" Visible="True">Download File</asp:LinkButton>

</td>
</tr>
<tr>
<td>
Url Video File :
<a href='<%#Eval("Url")%>' target="_blank"><%#Eval("Url")%></a>
</td>
</tr>
</ItemTemplate>
</asp:TemplateField>

</Columns>
if (e.Row.RowType == DataControlRowType.DataRow)
{
{
LinkButton lnk = (LinkButton)e.Row.FindControl("LinkButton1");
if (!String.IsNullOrEmpty(lnk.Text))
{
lnk.Visible = true;
}
else
{
lnk.Visible = false;
}
}
}

Advance Thanks to all

Responses
 Author : Manoranjan Sahoo Member Level : BronzeDate : 19/07/2011 04:48:27 PM Points : 2

Hello,

i am not getting your point. Can you please explain clearly what you want to do?

i are having two links in gridview. one is html's anchor tag and another is link button. 

but i am not getting your query here.

please explain. so that i can give you proper solution.

Thank you.



 Author : chandru M Member Level : BronzeDate : 19/07/2011 05:21:22 PM Points : 2

hi,

am using linkbutton and href link.linkbutton purpose for downloading use. href page redirect.

user post for any videofile using upload control some time post in url. but post in any one type only.visible for one link another one hide..because post in one link only. how that detail coding also post me.

 

AdvanceThanks



 Author : Manoranjan Sahoo Member Level : BronzeDate : 19/07/2011 05:47:36 PM Points : 2

if you want to save both link and display one then you can fetch only one. write one query like below and bind the result set to gridview.

string strSQL="select lnk, 'Url'=(case when (lnk is null or lnk='') then Url end)  from TableName";

Hope this will help you. if you have any other problem then let me know.

If it solve then mark this as answer.

Thank You.



 Author : chandru M Member Level : BronzeDate : 19/07/2011 06:21:54 PM Points : 2

hi,

  ur query is ok.but do not display for href link only display in download link.because db stored in empty.wave download path default..

am using insert in store procedure. so empty file not accepted.so am insert default value empty.wave set



 Author : chandru M Member Level : BronzeDate : 19/07/2011 06:24:43 PM Points : 2

hi,

  ur query is ok.but do not display for href link only display in download link.because db stored in empty.wave download path default..

am using insert in store procedure. so empty file not accepted.so am insert default value empty.wave set

Adavance Thanks



 Author : Manoranjan Sahoo Member Level : BronzeDate : 19/07/2011 06:40:35 PM Points : 2

you insert empty.wave in which field?



 Author : chandru M Member Level : BronzeDate : 19/07/2011 07:28:22 PM Points : 2

hi,

dummy field..

 



 Author : Manoranjan Sahoo Member Level : BronzeDate : 19/07/2011 07:37:04 PM Points : 2

i want to know which field of your database table. means link field or Url field?



 Author : chandru M Member Level : BronzeDate : 19/07/2011 07:57:21 PM Points : 2

link field Uploadvideo



 Author : Manoranjan Sahoo Member Level : BronzeDate : 19/07/2011 08:01:35 PM Points : 2

what is the field datatype of that field?

 



 Author : chandru M Member Level : BronzeDate : 19/07/2011 08:04:53 PM Points : 2

datatype varchar



 Author : Manoranjan Sahoo Member Level : BronzeDate : 19/07/2011 08:25:08 PM Points : 2



 Author : Manoranjan Sahoo Member Level : BronzeDate : 20/07/2011 05:31:03 AM Points : 2

then you can use the below code for that :

string strSQL="select lnk, 'Url'=(case when (lnk is null or lnk='empty.wave') then Url end)  from TableName";

i think this will help you.



 Author : chandru M Member Level : BronzeDate : 20/07/2011 01:22:59 PM Points : 2

hi,

am posting in some url but display in link and url link.

i want only display in any one link

Thanks



 Author : Manoranjan Sahoo Member Level : BronzeDate : 20/07/2011 01:48:57 PM Points : 2

try below query :

string strSQL="select lnk, 'Url'=(case when (lnk is null or  lnk='empty.wave') then Url when (lnk is not null and not  lnk='empty.wave') then '' end)  from TableName";

If you have the same problem again then let me know and post your code and also give one example what you exactly want. so that i will give you the perfect answer.

Thank You.



 Author : chandru M Member Level : BronzeDate : 20/07/2011 03:07:03 PM Points : 2

hi,

protected void imgbtnupload_Click(object sender, ImageClickEventArgs e)
    {
        SqlConnection con = new SqlConnection(strCS);

        if (fileVideofile.HasFile)
        {
            //Save File to the proper directory
            string filename = Path.GetFileName(fileVideofile.FileName);
            fileVideofile.SaveAs(Server.MapPath("UploadFiles/") + filename);
            Videofile = "UploadFiles/" + fileVideofile.FileName;
           //fileVideofile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("UploadFiles/") + fileVideofile.FileName);
           //Videofile = "UploadFiles/" + fileVideofile.FileName;
        }
        else
        {
            Videofile = "empty.wave";
            fileVideofile.SaveAs(Server.MapPath("UploadFiles/") + Videofile);
        }
      
        GetUserInfo UI = new GetUserInfo();
        Username = UI.getUserName(Session["User"].ToString());

        if (lblVideoId.Text == "")
        {
            con.Open();

            SqlCommand cmd = new SqlCommand("sp_add_tblVideo", con);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@VideoTitle", txtVideoTitle.Text);
            cmd.Parameters.AddWithValue("@VideofileDesc", txtVideofileDesc.Text);
            cmd.Parameters.AddWithValue("@Category", ddlVideoCat.SelectedItem.ToString());
            cmd.Parameters.AddWithValue("@Uploadimages",Videofile);
            cmd.Parameters.AddWithValue("@Author", Username.ToString());
            cmd.Parameters.AddWithValue("@Url", txtUrl.Text);
          
            cmd.ExecuteNonQuery();
            con.Close();
        }
        else
        {
            //Updated related datas
            UpdateVideofile();
        }
        SqlCommand cmd1 = new SqlCommand("select VideoId from tblVideo where VideoTitle='" + txtVideoTitle.Text + "'", con);
        con.Open();
        SqlDataReader dr;
        dr = cmd1.ExecuteReader();
        if (dr.Read())
        {
            VideoId = dr[0].ToString();
        }
        con.Close();
        Response.Redirect("ViewVideofiles.aspx?VideoId=" + VideoId + "&Uploadimages=" + Videofile);

    }

this is insert coding..

after go view page

download link coding:

protected void LinkButton1_Click(object sender, EventArgs e)
    {
            string FilePath = Server.MapPath(Request.QueryString["Uploadimages"].ToString());
            System.IO.FileInfo TargetFile = new System.IO.FileInfo(FilePath);
            if (TargetFile.Exists)
            {
                Response.Clear();
                Response.AddHeader("Content-Disposition", "attachment; filename=" + TargetFile.Name);
                Response.AddHeader("Content-Length", TargetFile.Length.ToString());
                Response.ContentType = "mp3/mp4";
                Response.WriteFile(TargetFile.FullName);

            }
            UserInfoBAL uiBAL = new UserInfoBAL();

            uiBAL.UpdateDownloadpoints(Request.QueryString["Author"].ToString());
          uiBAL.UpdateDownloadpoints(Session["User"].ToString());
     
    }

another code also provide



 Author : Manoranjan Sahoo Member Level : BronzeDate : 20/07/2011 03:16:33 PM Points : 2

Then you need to change the retrieving query like below :

string strSQL="select lnk, 'Url'=(case when (lnk is null or  lnk='UploadFiles/empty.wave') then Url when (lnk is not null and not  lnk='UploadFiles/empty.wave') then '' end)  from TableName";

try above. if you have any problem then let me know with your retrieve code.

 



 Author : chandru M Member Level : BronzeDate : 20/07/2011 03:21:33 PM Points : 2

hi,

upload file save in database empty.wave that is not problem.

my reterive code

  protected void GridVideofile_RowDataBound(object sender, GridViewRowEventArgs e)
    {
       
           if (e.Row.RowType == DataControlRowType.DataRow)
        {
            {
                LinkButton lnk = (LinkButton)e.Row.FindControl("LinkButton1");

                if (!String.IsNullOrEmpty(lnk.Text))
                {
                    lnk.Visible = true;
                }
                else
                {
                    lnk.Visible = false;
                }
            }

 public void GetVideofile()
    {
        SqlConnection con = new SqlConnection(strCS);
        SqlDataAdapter da = new SqlDataAdapter("select VideoId,VideoTitle,VideofileDesc,Category,Uploadimages,'Url'=(case when (Uploadimages is null or Uploadimages='empty.wave') then Url when (Uploadimages is not null and not  Uploadimages='empty.wave') then '' end),Author,points,ViewCount,Image,Dateofpost,Convert(CHAR(10),Dateofpost,101) as Jdate from tblVideo where VideoId='" + Request.QueryString["VideoId"] + "'", con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        GridVideofile.DataSource = ds;
        GridVideofile.DataBind();

    }

also provide design code yesterday

 

Thanks



Post Reply
Login to post Response.