如何从asp.net后面的代码动态初始化GridView边界域,模板和项目模板并为其提供价值

时间:2017-10-20 18:42:32

标签: c# sql asp.net gridview dynamic

我在我的aspx文件中有这个代码,用于显示来自sql的数据,只为这个GridView提供数据源。

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="true">
        <Columns>
            <asp:BoundField DataField ="CNIC" HeaderText ="CNIC"/>
            <asp:BoundField DataField ="Name" HeaderText ="Name"/>
            <asp:BoundField DataField ="FatherName" HeaderText ="Father Name"/>
            <asp:BoundField DataField ="Gender" HeaderText ="Gender"/>
            <asp:BoundField DataField ="DOB" HeaderText ="Date of birth"/>
            <asp:BoundField DataField ="maritalStatus" HeaderText ="Marital Status"/>
            <asp:BoundField DataField ="religion" HeaderText ="Religion"/>
            <asp:BoundField DataField ="postalAddress" HeaderText ="Postal Address"/>
            <asp:BoundField DataField ="permenantAddress" HeaderText ="Permenant Address"/>
            <asp:BoundField DataField ="email" HeaderText ="Email Address"/>
            <asp:BoundField DataField ="telephoneNumber" HeaderText ="Telephon Number"/>
            <asp:BoundField DataField ="cellPhoneNumber" HeaderText ="Cellphone Number"/>
            <asp:TemplateField HeaderText ="Photo">
                <ItemTemplate>
                    <asp:Image ID="Image2" Height="100px" Width="100px" ImageUrl ='<%#"data:Image/png;base64," + Convert.ToBase64String((byte[])Eval("photo")) %>' runat="server"></asp:Image>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField ="passportNumber" HeaderText ="Passport Number"/>
            <asp:BoundField DataField ="passportValidity" HeaderText ="Passport Validity"/>
            <asp:BoundField DataField ="dualNationality" HeaderText ="Dual Nationality"/>
            <asp:BoundField DataField ="nationality" HeaderText ="Nationality"/>
            <asp:BoundField DataField ="nationalitySince" HeaderText ="Nationality since"/>
            <asp:BoundField DataField ="policeVerification" HeaderText ="Police verification"/>
            <asp:TemplateField HeaderText ="Signature">
                <ItemTemplate>
                    <asp:Image ID="Image3" Height="100px" Width="100px" ImageUrl ='<%#"data:Image/png;base64," + Convert.ToBase64String((byte[])Eval("piSignature")) %>' runat="server"></asp:Image>
                </ItemTemplate>
            </asp:TemplateField>

        </Columns>
    </asp:GridView>

这段代码工作正常,但我需要从代码隐藏文件动态执行。我只想在我的aspx文件中使用<asp:GridView ID="GridView2" runat="server"> </asp:GridView>并从代码中完成所有其余工作,请帮助我。< / p>

0 个答案:

没有答案