Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello! I have a GridView with data bound fields from a mysql database. It contains two columns IdTask(primary key),
TaskName and one button which opens a jQuery dialog.
I need to fill this dialog based on the on the ID of the task from the row i clicked the button.
And i have a user control with another Gridview which contains said data that i need to display in the dialog.

This is what i have so far:

The aspx Page:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register TagPrefix="ucFiles" TagName="Files" Src="~/UserControlFiles.ascx" 

the script: 
<script>
       $(document).ready(function () {
            $(".btnFiles").click(function () {
                
                $("#divModalFiles").dialog({
                    dialogClass: "no-close",
                    modal: true,
                    title: "Files",
                    width: 450,
                    height: 440,
                    buttons: {
                        Close: function () {
                            $(this).dialog('close');
                        }
                    },
                    open: function (type, data) {
                        $(this).parent().appendTo("form");
                    }
                    
                });
                return false;
            });
        });
    </script>
<form id="form1" runat="server" style="padding: 10px; width: 550px">
	<asp:GridView DataKeyNames="IdTask" ID="gvTask" runat="server"
        AutoGenerateColumns="false">
		<Columns>
                <asp:BoundField DataField="IdTask" HeaderText="ID" />
                <asp:BoundField DataField="Name" HeaderText="Task"  />
		<asp:TemplateField>
                        <ItemTemplate>
                            <asp:ImageButton ID="btnFile" CssClass="btnFiles" runat="server" ImageUrl="img/files.png.png"/>
                        </ItemTemplate>
                </asp:TemplateField>
 		</Columns>
        </asp:GridView>
	<div id="divModalFiles" style="display:none">
            <ucFiles:Files runat="server"/>
        </div>
</form>
</body>

The ascx userControl:
<div id="file">
          <asp:Literal ID="litMesaj" runat="server" Visible="false"></asp:Literal>
          <asp:FileUpload ID="fUpload" runat="server" />
          
          <br />
          <br />
          <asp:Label ID="lblDescFile" runat="server" Text="Description"></asp:Label>
          <asp:TextBox ID="txtDescFile" runat="server" ></asp:TextBox>
          <asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="btnUpload_Click" />
          <br />
          <br />
           
          <asp:GridView ID="gvFiles" DataKeyNames="IdFiles" runat="server" AutoGenerateColumns="false" EmptyDataText="No files uploaded">
              <Columns>
                  <asp:BoundField DataField="IdFiles" HeaderText="ID" />
                  <asp:BoundField DataField="IdTask" HeaderText="IdTask" />
                  <asp:BoundField DataField="Name" HeaderText="File Name" />
                  <asp:BoundField DataField="Description" HeaderText="Description" />

                  <asp:TemplateField>
                      <ItemTemplate>
                          <asp:LinkButton ID="lnkDownload" runat="server" Text="Download File" OnClick="lnkDownload_Click" CommandArgument='<%# Eval("Url") %>'></asp:LinkButton>
                      </ItemTemplate>
                  </asp:TemplateField>
                  <asp:TemplateField>
                      <ItemTemplate>
                          <asp:ImageButton runat="server" ID="btnDelFile" ImageUrl="~/delete.png.png" OnClientClick="return confirm('Sure?');" OnClick="btnDelFile_Click"/>
                      </ItemTemplate>
                  </asp:TemplateField>
              </Columns>              
          </asp:GridView>
      </div>  

The ascx.cs userControl:

// the function i call in page load to display the files
private void loadFiles()
   {
       string sqlFiles = "select * from files where IdTask=" + ?? ;// here is where i need the help how can i retrieve the IdTask from the gridview on the aspx Page?
       MySqlCommand cmd = new MySqlCommand(sqlFiles, conn);

   MySqlDataAdapter adp = new MySqlDataAdapter(cmd);
   DataTable dtFiles = new DataTable();
   adp.Fill(dtFiles);
       gvFiles.DataSource = dtFiles;
       gvFiles.DataBind();
   }


Can you help me ? without that ID i can't use the download or the upload files functions either. It currently shows only the form with the files upload and the upload button
If i didn't made myself clear(English is not my first language) with what i need please feel free to ask any questions and i will explain :)

EDIT:

I also want to add that in the database i have 2 tables:
1. IdTask, Task
2. IdFile, IdTask, FileName, etc..

so each task has a coresponding file

What I have tried:

watching all sorts of tutorials and still don't have a solution
Posted
Updated 2-Feb-17 22:10pm
v4

I think you are asking how to fetch ID in C# variable. If that is what you are saying.
Then it is simple.
Var ID = gvFiles.Rows[e.RowIndex].Cells[0].Text;
 
Share this answer
 
Comments
Member 12869977 3-Feb-17 3:14am    
Thank you for your answer but no, what you have wrote gives the id of the file and i don't need that, i need to pass the value of the id of the task from the aspx gridview, the one with the tasks, into the user control page and use it there so i can display download and upload files. Please see updated question for better understanding.
As I understand what you are going to say, you are not able to get "IdTask", This can be resolve by passing two arguments in command argument hope it will answer for you.

ASP.NET
<pre><asp:templatefield>
<itemtemplate>
<asp:LinkButton ID="lnkDownload" runat="server" Text="Download File" OnClick="lnkDownload_Click" CommandArgument='<%# Eval("Url")+ ";" +Eval("IdTask")>'></asp:LinkButton>
    </itemtemplate>
</asp:templatefield>

Then you get id and url which is available in command argument. you need to split itthen you will get both ID and URL

C#
string strVal = e.CommandArgument.ToString();
    string[] arg = new string[2];
    char[] splitter = { ';' };
    arg = strVal .Split(splitter);
    string strUrl = arg[0].ToString();
    string strIdTask = arg[1].ToString();
 
Share this answer
 
v2

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