0
두 개의 열이있는 눈금보기가 있습니다. 하나는 제품이고 다른 하나는 값 (템플릿 필드의 두 열)입니다.gridview의 텍스트 상자를 사용하여 데이터베이스 테이블에 값 삽입
제품 열은 "제품"테이블에 바인딩됩니다. 값 필드의 항목 템플리트에는 텍스트 상자가 있습니다.
격자보기의 텍스트 상자를 통해 데이터베이스 테이블 "BrandProperties"에 값을 삽입해야하지만이 작업을 수행하는 방법을 잘 모르겠습니다.
이if (!IsPostBack)
{
BindView();
}
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter("select ID,TypeName from ProductTypes",con);
da.Fill(dt);
DropDownList1.DataSource = dt;
DropDownList1.DataValueField = "ID";
DropDownList1.DataTextField = "TypeName";
DropDownList1.DataBind();
}
public void BindView()
{
DataTable dt = new DataTable();
string sql = "select * from Properties";
con.Open();
SqlDataAdapter da = new SqlDataAdapter(sql, con);
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
con.Close();
}
aspx.code :
Text="Brand Name"></asp:Label>
<asp:Button ID="Button1" runat="server" BackColor="#6699FF"
style="z-index: 1; left: 410px; top: 391px; position: absolute"
Text="SAVE" onclick="Button1_Click" />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px"
CellPadding="3" GridLines="Horizontal"
style="z-index: 1; left: 52px; top: 230px; position: absolute; height: 133px; width: 344px">
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<Columns>
<asp:TemplateField HeaderText="Product">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("PropertyName") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Value">
<ItemTemplate>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
을 시도
여기 내 코드입니다. 나는 이것에 대한 게시물을 작성했습니다. Refer = http://satindersinght.blogspot.in/2012/08/how-to-addupdate-record-using-gridview.html –
하지만 항목 템플릿을 사용하여 새 항목을 추가해야합니다. 텍스트 상자 : (그 값은 데이터베이스에 저장되어야합니다.) – user2404367
: 필자가 알고있는 바로는 'ItemTemplate'은 데이터를 표시하는 데 사용되고,'EditTemplate'은 업데이트를 사용하고 'FootTemplate'은 새 항목을 추가하는 데 사용됩니다. 귀하의 경우 항목 템플릿을 편집 할 수 있습니까? 사용자가 볼 수/편집 할 수 있습니다 –