2014-10-31 3 views
0

gridview에 대한 간단한 예제를 작성했는데 그 이유는 알 수 없지만 gridview는 웹 사이트에 전혀 없습니다. 아무것도 ... http://ipic.su/img/img7/fs/example.1414716455.jpgSQL Server 데이터베이스에서 페이지로드시 gridview가 표시되지 않습니다.

누군가가 어떤 실수를 볼 수 - 여기

내가 브라우저에서 무엇을 얻을 그림이 무엇입니까?

<%@Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Site.Master" CodeFile="InvoiceEdit.aspx.cs" Inherits="InvoiceEdit" EnableEventValidation="false" %> 

<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent"> 
    <style> 
.gridview 
{ 
    background: red; 
    border:dashed 1px blue; 
} 
</style> 
    <asp:GridView ID="gvInvoice" runat="server"    
    AutoGenerateColumns="False" 
    OnRowDataBound="gvInvoice_RowDataBound" 
    DataKeyNames="InvoiceID" 
    AutoGenerateEditButton="False" 
    CellPadding="1" Width="100%" 
    datasourceid="SqlDataSource1" 
    CssClass ="gridview"> 
<Columns > 
    <asp:BoundField HeaderText="InvoiceID" DataField="InvoiceID" ReadOnly="true" /> 
    <asp:BoundField HeaderText="RechnNummer" DataField="RechnNummer" ReadOnly="true" /> 
    <asp:BoundField HeaderText="Kunde" DataField="Kunde" ReadOnly="true" /> 
    <asp:BoundField HeaderText="Text" DataField="Text" ReadOnly="true"/>    
</Columns> 
</asp:GridView> 
----TEST TEXT---- 
<asp:sqldatasource id="SqlDataSource1"   
    selectcommand="Select * from Invoice where InvoiceID = @InvoiceID" 
    updatecommand="Update Invoice set RechnNummer = @RechnNummer, [email protected], [email protected], [email protected], [email protected], 
        [email protected], [email protected], [email protected] where InvoiceID = @InvoiceID"   
    connectionstring="<%$ ConnectionStrings:Invoice%>" 
    runat="server" >  
    <SelectParameters> 
     <asp:ControlParameter ControlID="gvInvoice" PropertyName="SelectedValue" Name="InvoiceID" /> 
    </SelectParameters> 
    <UpdateParameters> 
     <asp:ControlParameter ControlID="gvInvoice" PropertyName="SelectedValue" Name="InvoiceID" /> 
    </UpdateParameters> 
    </asp:sqldatasource> 
</asp:Content> 

코드 숨김이 거의 비어 있지만 문제가되지 않는다고 생각합니다. 라이브러리가 누락 되었습니까? 또는 무엇이 잘못 되었습니까? 대답 주셔서 감사합니다!

public partial class InvoiceEdit : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    {  
    } 

    protected void gvInvoice_RowDataBound(object sender, GridViewRowEventArgs e) 
    { 
     if (e.Row.RowType == DataControlRowType.DataRow) 
     { 
      e.Row.Attributes.Add("onmouseover", "this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='#C2C2C2'"); 
      e.Row.Attributes.Add("onmouseout","this.style.backgroundColor=this.originalstyle;"); 
      e.Row.Attributes["style"] = "cursor:pointer"; 
     } 
    } 
} 
+0

데이터 소스를 확인하십시오. 어떤 데이터가 있습니까? – Sam

+0

이 그림을 보시라. http://ipic.su/img/img7/fs/example.1414719295.jpg 디자인 모드를 사용하면 gridview를 볼 수는 있지만 편집 할 수 없다 ... hm . 슬프게도,하지만 내가 어떤 오류가 발생하지, 그것은 처음으로 내게 일어납니다 – Therapyx

+0

디자인 모드는 단지 당신에게 몇 가지 더미 데이터를 보여줍니다. 데이터베이스에서 데이터를 가져 오는 것은 아닙니다. 데이터 원본을 살펴보십시오. 연결 문자열은 어디에 있습니까? 그 정확한지 확인하십시오 – Sam

답변

0

시도 this 데이터 소스 코드를

<asp:TextBox ID="txtInvoiceID" runat="server"></asp:TextBox> 

변경 선택 문 및 매개 변수 선택 :

는 텍스트 필드를 추가

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Invoice %>" 
    SelectCommand="Select * from Invoice where InvoiceID = @InvoiceID OR @InvoiceID IS NULL" CancelSelectOnNullParameter="false"> 
    <SelectParameters> 
     <asp:QueryStringParameter Name="InvoiceID" DbType = "String" Direction = "Input" QueryStringField="Id" DefaultValue="" ConvertEmptyStringToNull="True" /> 
    </SelectParameters> 
</asp:SqlDataSource> 

코드 뒤에 :

protected void Page_Load(object sender, EventArgs e) 
{ 
    if (!IsPostBack) 
    { 
     txtInvoiceID.Text = Request.QueryString["Id"]; 
    } 
} 

protected void btnRedirect_Click(object sender, EventArgs e) 
{ 
    Response.Redirect("~/Default.aspx?Id=" + txtInvoiceID.Text.Trim()); 
} 

당신은 SQL 매개 변수를 추가해야합니다 .. DataGrid에 데이터가 없으므로 DataGrid가 보이지 않습니다.

+0

고마워,하지만 난 밤새도록 일하고 있었고 마지막으로이 문제를 해결했다. SQL 연결이 도청 (dono 이유)했다, 난 그냥 한 번도 null에서 않았다 – Therapyx

관련 문제