如何在数据库中匹配id后获取数据?

时间:2012-02-15 08:06:48

标签: asp.net c#-4.0

您好我正在开发一个web应用程序,其中经理从网格中为员工分配工作..

我有像这样的数据库表

     ManagerTable
      Customerid
      name
      and some other columns
     EmployeeTable
     empid
      employeeName
     Worktable
      CustomerID
      EmpID

数据库:

Table 1                                               Table 2
CustomerID | CustomerName|CustomerAddress          EmpID |EmpName
---------                                          -------------------
 1 | One    |--|--                                 1 | EmployeeName
 2 | Two                                           2 | EmployeeName
 3 | Three

            Table 3
            Tb1 | Tb2
            ---------
//            1 | 1
//            1 | 2

当经理为具有唯一ID(例如,CustomerID,EmployeeID)的partcualr员工分配复选框时,应该存储在工作表中的按钮上,我必须使用存储在表格中的IDS从工作表中检索数据并显示他们在网格

当员工用他的身份登录时,应检查并在网格中获取数据,所有员工都有相同的网页

任何人都可以帮助我查询和代码将是最有帮助的...

1 个答案:

答案 0 :(得分:1)

我遇到了与你相同的问题我希望你在网格中使用模板...给checkBox一些id ...例如我在我的例子中给出了“Chkselect”id为复选框...我dnt你怎么给你的桌子两个...但在我的例子中有bindde表2下拉然后按钮点击每个东西运行...

           Aspx

           <obout:Column DataField="CUSTOMER_LOAN_NO" HeaderText="CUSTOMER_LOAN_NO"  ReadOnly="true">
       <%-- <TemplateSettings RowEditTemplateControlId="txtCustmLn" RowEditTemplateControlPropertyName="value"/>  --%>    
       <TemplateSettings TemplateId="ChkSelect1" />      
        </obout:Column> 

<obout:GridTemplate ID="ChkSelect1" runat="server" >
        <Template>
        <obout:OboutCheckBox runat="server" ID="Chkselect"  ToolTip="<%# Container.Value %>"  ></obout:OboutCheckBox>
        </Template>
        </obout:GridTemplate>   


    Aspx page behind code


            void grid1_RowDataBound(object sender, GridRowEventArgs e)
{
    if (e.Row.RowType == GridRowType.DataRow && GrdCustomerData.RowsInViewState.Count > 0)
    {
        GridDataControlFieldCell cell = e.Row.Cells[0] as GridDataControlFieldCell;
        CheckBox chk = cell.FindControl("Chkselect") as CheckBox;

        GridDataControlFieldCell cellInViewState = GrdCustomerData.RowsInViewState[e.Row.RowIndex].Cells[0] as GridDataControlFieldCell;
        CheckBox chkInViewState = cellInViewState.FindControl("Chkselect") as CheckBox;

        if (cell.Value == chkInViewState.ToolTip)
        {
            chk.Checked = chkInViewState.Checked;
        }
    }
}

protected void BtnAssignWork_Click(object sender, EventArgs e)
{
    string LoanIds = "";

    for (int i = 0; i < GrdCustomerData.RowsInViewState.Count; i++)
    {
        GridDataControlFieldCell cell = GrdCustomerData.RowsInViewState[i].Cells[0] as GridDataControlFieldCell;
        CheckBox chk = cell.FindControl("Chkselect") as CheckBox;

        if (chk.Checked == true)
        {
            if (!string.IsNullOrEmpty(LoanIds))
               LoanIds += "";

           LoanIds = chk.ToolTip;
                    SqlConnection myconn = new SqlConnection(connstring);
                    SqlCommand mycomm = new SqlCommand("SP_AssignedWork", myconn);
                    myconn.Open();
                    mycomm.CommandType = CommandType.StoredProcedure;
                    mycomm.Parameters.Add("@LoanID", SqlDbType.VarChar).Value = LoanIds;
                    mycomm.Parameters.Add("@EmpID", SqlDbType.VarChar).Value = DDLSelectEmployee.SelectedValue;
                    mycomm.ExecuteNonQuery();
                    myconn.Close();
                }
            }


        }
    }

我希望这会有所帮助......