빈 템플릿 후 GridView가 데이터 테이블과 바인딩되지 않음

나는 뒷받침한다

GridView의 빈 템플릿을 통해 데이터를 삽입하면 .. 값이 DB에 삽입되지만 Gridview는 삽입 후 해당 값과 바인딩 (프로그래밍 방식으로 수행)되지 않으므로 삽입 된 값이 표시되지 않습니다.

여기에 코드를 짧게 유지하기 위해 dbms 테이블의 ques 필드에 하나의 값만 삽입합니다.

GridView HTML 태그 코드

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" ShowFooter="True" Height="146px" style="margin-top: 5px" Width="866px" >
                <Columns>
                    <asp:TemplateField HeaderText="qno">
                        <FooterTemplate>
                            <asp:TextBox ID="qno" runat="server"></asp:TextBox>
                        </FooterTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Ques">
                        <FooterTemplate>
                            <asp:TextBox ID="ques" runat="server" Height="16px" Width="78px"></asp:TextBox>
                        </FooterTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="op1">
                        <FooterTemplate>
                            <asp:TextBox ID="op1" runat="server" Height="16px" Width="76px"></asp:TextBox>
                        </FooterTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="op2">
                        <FooterTemplate>
                            <asp:TextBox ID="Top2" runat="server" Height="16px" Width="74px"></asp:TextBox>
                        </FooterTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="op3">
                        <FooterTemplate>
                            <asp:TextBox ID="op3" runat="server" Height="16px" Width="74px"></asp:TextBox>
                        </FooterTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="op4">
                        <FooterTemplate>
                            <asp:TextBox ID="op4" runat="server"></asp:TextBox>
                        </FooterTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="ans">
                        <FooterTemplate>
                            <asp:TextBox ID="ans" runat="server"></asp:TextBox>
                        </FooterTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="marks">
                        <FooterTemplate>
                            <asp:TextBox ID="marks" runat="server"></asp:TextBox>
                        </FooterTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="UploadImage">
                        <FooterTemplate>
                            <asp:TextBox ID="imageP" runat="server"></asp:TextBox>
                        </FooterTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField>
                        <FooterTemplate>
                            <asp:Button ID="Button2" runat="server" Text="save" Width="78px" OnClick="Button2_Click1" />
                        </FooterTemplate>
                    </asp:TemplateField>
                </Columns>


                 <EmptyDataTemplate>
    <tr style="background-color: Green;">
        <th scope="col">
            qno
        </th>
        <th scope="col">
            ques
        </th>
        <th scope="col">
            op1
        </th>
        <th scope="col">
            op2
        </th>
        <th scope="col">
            op3
        </th>
        <th scope="col">
            op4
        </th>
        <th scope="col">
            ans
        </th>
        <th scope="col">
            marks
        </th>
        <th scope="col">
            imageP
        </th>
        <th scope="col">

        </th>
    </tr>
    <tr>
        <td>
            <asp:TextBox ID="qno" runat="server" Height="16px" Width="68px" />
        </td>
        <td>
            <asp:TextBox ID="ques" runat="server" Height="16px" Width="68px" />
        </td>
        <td>
            <asp:TextBox ID="op1" runat="server" Height="16px" Width="68px" />
        </td>
        <td>
            <asp:TextBox ID="op2" runat="server" Height="16px" Width="68px" />
        </td>
        <td>
            <asp:TextBox ID="op3" runat="server" Height="16px" Width="68px" />
        </td>
        <td>
            <asp:TextBox ID="op4" runat="server" Height="16px" Width="68px" />
        </td>
        <td>
            <asp:TextBox ID="ans" runat="server"  Height="16px" Width="68px"/>
        </td>
        <td>
            <asp:TextBox ID="marks" runat="server"  Height="16px" Width="68px"/>
        </td>
        <td>
            <asp:TextBox ID="imageP" runat="server"  Height="16px" Width="68px"/>
        </td>

        <td>
            <asp:Button ID="Button2" runat="server" Text="Add" OnClick="Button2_Click1" CommandName = "EmptyDataTemplate" />
        </td>
    </tr>
</EmptyDataTemplate>

            </asp:GridView>

C # 코드 :

public partial class qpaper : System.Web.UI.Page
{
String conStr = "Data Source=temporary; Initial Catalog=temporary1;Integrated Security=True";
String qpname = null;


protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        this.BindData();
    }
}





private void BindData()
{

    DataTable dt = new DataTable();
    using (SqlConnection con = new SqlConnection(conStr))
    {
        string strQuery = "SELECT * FROM dbms";
        SqlCommand cmd = new SqlCommand(strQuery);
        using (SqlDataAdapter sda = new SqlDataAdapter())
        {
            cmd.Connection = con;
            con.Open();
            sda.SelectCommand = cmd;
            sda.Fill(dt);
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }
    }
}




protected void Button2_Click1(object sender, EventArgs e) // save button in gridview/empty template
{

    Control control = null;
    if (GridView1.FooterRow != null)
    {
        control = GridView1.FooterRow;
    }
    else
    {
        control = GridView1.Controls[0].Controls[0];
    }
    string ques = (control.FindControl("ques") as TextBox).Text;

    using (SqlConnection con = new SqlConnection(conStr))
    {
        using (SqlCommand cmd = new SqlCommand())
        {
            cmd.Connection = con;
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "insert into dbms (ques) VALUES (@ques)"; //inserting only one value here for shortening code length
            cmd.Parameters.AddWithValue("@ques", ques);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
        }
    }
    Response.Redirect(Request.Url.AbsoluteUri);

}

}

테이블 구조 :

qno int , ques nvarchar(500), op1 nvarchar(50), op2 nvarchar(50), op3 nvarchar(50), op4 nvarchar(50), ans nvarchar(50), marks int, imagePath nvarchar(200)
mjb

자동 바인딩이 작동하려면 BoundField 인 열이 하나 이상 있어야합니다.

예 : 작동하지 않습니다.

<asp:GridView ID="GridView1" AutoGenerateColumns="false" runat="server">
    <Columns>
        <asp:TemplateField HeaderText="Name">
            <ItemTemplate>
                <asp:TextBox Id="txtName" runat="server"></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Address">
            <ItemTemplate>
                <asp:TextBox ID="txtAddress" runat="server"></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

이것은 작동합니다

<asp:GridView ID="GridView1" AutoGenerateColumns="false" runat="server">
    <Columns>
        <asp:BoundField HeaderText="ID" DataField="id" />
        <asp:TemplateField HeaderText="Name">
            <ItemTemplate>
                <asp:TextBox Id="txtName" runat="server"></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Address">
            <ItemTemplate>
                <asp:TextBox ID="txtAddress" runat="server"></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Vue js 데이터가 템플릿에 표시되지 않음

분류에서Dev

model.save () 후 템플릿이 업데이트되지 않음

분류에서Dev

knockoutjs로 ajax를 호출 한 후 데이터가 바인딩되지 않음

분류에서Dev

디렉티브 템플릿이 templateUrl을 통해로드 될 때 ng-repeat가 바인딩되지 않음

분류에서Dev

템플릿보기 AngularJS에 json 데이터가 표시되지 않음

분류에서Dev

Ember 모델 데이터가 템플릿에 표시되지 않음

분류에서Dev

간단한 유성 템플릿에 데이터가 표시되지 않음

분류에서Dev

meteor 앱-템플릿 도우미가 데이터를 반환하지 않을 때 빈 템플릿을 표시하는 방법

분류에서Dev

Rails ActionMailer 템플릿 업데이트가 적용되지 않음

분류에서Dev

Angular 2 템플릿 변수가 업데이트되지 않음

분류에서Dev

내 검도 템플릿 필드가 그리드 열의 데이터를 바인딩하지 않습니다.

분류에서Dev

$ scope가 $ apply () 이후 템플릿 내부의 데이터를 새로 고치지 않습니다.

분류에서Dev

데이터 템플릿이 표시되지 않음

분류에서Dev

내보내기 후 Eclipse 플러그인 템플릿이 작동하지 않음

분류에서Dev

후보로 확인되지 않은 컨테이너에 대한 템플릿 연산자 템플릿

분류에서Dev

Meteor-사용자 로그인 후 템플릿이 업데이트되지 않음

분류에서Dev

데이터 테이블 효과가 표시되지 않음

분류에서Dev

Angular 템플릿이로드되지 않습니다. $ loaded로도. 로드 후 데이터 확인

분류에서Dev

Observable의 데이터 세트가 템플릿에서 업데이트되지 않음

분류에서Dev

ItemsControl을 사용한 계층 데이터 템플릿 바인딩이 작동하지 않음-WPF

분류에서Dev

업로드 후 새 프로세스 템플릿이 적용되지 않음

분류에서Dev

데이터 그리드 데이터 템플릿의 항목 소스가 작동하지 않음

분류에서Dev

데이터 흐름 템플릿-Splunk가 주제에서 데이터를 읽지 않음

분류에서Dev

새로운 '빈 활동'템플릿 앱에 머티리얼 디자인이 표시되지 않음

분류에서Dev

템플릿의 kendo ui 모바일 이벤트가 실행되지 않음

분류에서Dev

테이블 데이터가 업데이트 된 후 jQuery DataTable 정렬이 업데이트되지 않음

분류에서Dev

테이블 데이터가 업데이트 된 후 jQuery DataTable 정렬이 업데이트되지 않음

분류에서Dev

캐시 된 템플릿의 각도 지시문이 제대로 바인딩되지 않음

분류에서Dev

템플릿 데이터 바인딩

Related 관련 기사

  1. 1

    Vue js 데이터가 템플릿에 표시되지 않음

  2. 2

    model.save () 후 템플릿이 업데이트되지 않음

  3. 3

    knockoutjs로 ajax를 호출 한 후 데이터가 바인딩되지 않음

  4. 4

    디렉티브 템플릿이 templateUrl을 통해로드 될 때 ng-repeat가 바인딩되지 않음

  5. 5

    템플릿보기 AngularJS에 json 데이터가 표시되지 않음

  6. 6

    Ember 모델 데이터가 템플릿에 표시되지 않음

  7. 7

    간단한 유성 템플릿에 데이터가 표시되지 않음

  8. 8

    meteor 앱-템플릿 도우미가 데이터를 반환하지 않을 때 빈 템플릿을 표시하는 방법

  9. 9

    Rails ActionMailer 템플릿 업데이트가 적용되지 않음

  10. 10

    Angular 2 템플릿 변수가 업데이트되지 않음

  11. 11

    내 검도 템플릿 필드가 그리드 열의 데이터를 바인딩하지 않습니다.

  12. 12

    $ scope가 $ apply () 이후 템플릿 내부의 데이터를 새로 고치지 않습니다.

  13. 13

    데이터 템플릿이 표시되지 않음

  14. 14

    내보내기 후 Eclipse 플러그인 템플릿이 작동하지 않음

  15. 15

    후보로 확인되지 않은 컨테이너에 대한 템플릿 연산자 템플릿

  16. 16

    Meteor-사용자 로그인 후 템플릿이 업데이트되지 않음

  17. 17

    데이터 테이블 효과가 표시되지 않음

  18. 18

    Angular 템플릿이로드되지 않습니다. $ loaded로도. 로드 후 데이터 확인

  19. 19

    Observable의 데이터 세트가 템플릿에서 업데이트되지 않음

  20. 20

    ItemsControl을 사용한 계층 데이터 템플릿 바인딩이 작동하지 않음-WPF

  21. 21

    업로드 후 새 프로세스 템플릿이 적용되지 않음

  22. 22

    데이터 그리드 데이터 템플릿의 항목 소스가 작동하지 않음

  23. 23

    데이터 흐름 템플릿-Splunk가 주제에서 데이터를 읽지 않음

  24. 24

    새로운 '빈 활동'템플릿 앱에 머티리얼 디자인이 표시되지 않음

  25. 25

    템플릿의 kendo ui 모바일 이벤트가 실행되지 않음

  26. 26

    테이블 데이터가 업데이트 된 후 jQuery DataTable 정렬이 업데이트되지 않음

  27. 27

    테이블 데이터가 업데이트 된 후 jQuery DataTable 정렬이 업데이트되지 않음

  28. 28

    캐시 된 템플릿의 각도 지시문이 제대로 바인딩되지 않음

  29. 29

    템플릿 데이터 바인딩

뜨겁다태그

보관