C#,usercontrol:如何检索在usercontrol.ascx中使用的主键? [英] C#, usercontrol : how can I retrieve the primary key to use in a usercontrol.ascx?

查看:77
本文介绍了C#,usercontrol:如何检索在usercontrol.ascx中使用的主键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!我有一个GridView,其中包含来自mysql数据库的数据绑定字段。它包含两列IdTask(主键),

TaskName和一个用于打开jQuery对话框的按钮。

我需要根据有关的ID填写此对话框我点击按钮的行中的任务。

我有一个用户控件和另一个Gridview,其中包含我需要在对话框中显示的数据。



这就是我的意思到目前为止:



aspx页面:

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>



ascx userControl:


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>  



ascx.cs userControl:




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();
   }





你能帮助我吗?如果没有该ID,我也无法使用下载或上传文件功能。它目前只显示上传文件和上传按钮的表格

如果我没有说清楚(英语不是我的第一语言)我需要的东西请随时提出任何问题和问题我会解释:)



编辑:



我还想在数据库中添加我有2个表:

1. IdTask,任务

2. IdFile,IdTask,FileName等。



所以每个任务都有一个相应的文件



我尝试过:



观看各种教程但仍然没有解决方案



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 :)



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

推荐答案

(文档)。 ready(function(){
(document).ready(function () {


(。btnFiles)。click(function(){
(".btnFiles").click(function () {


(#divModalFiles)。dialog( {
dialogClass:no-close,
modal:true,
title:Files,
width:450,
身高:440,
按钮:{
关闭:function(){
("#divModalFiles").dialog({ dialogClass: "no-close", modal: true, title: "Files", width: 450, height: 440, buttons: { Close: function () {


这篇关于C#,usercontrol:如何检索在usercontrol.ascx中使用的主键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆