I have a following table tblData
DamID |
CalfTag |
B_Type |
Bread |
Loctation |
101 |
1010 |
H |
5 |
0 |
102 |
1020 |
H |
5 |
0 |
103 |
1030 |
H |
5 |
0 |
From above table I displayed few columns in the DataGridView like that
DamID |
CalfTag |
B_Type |
Action |
101 |
1010 |
H |
Update |
102 |
1020 |
H |
Update |
103 |
1030 |
H |
Update |
When I click on Update link button in each inside DataGridView, then it will fetch all five values from above tblData and when I click on update button it will save all the fetched values in another tblAnimal table which is following like that tblAnimal
DamName |
TagID |
B_Type |
Bread |
LocNo |
101 |
1010 |
H |
5 |
0 |
103 |
1030 |
H |
5 |
0 |
here is my code
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" ForeColor="#333333"
RowStyle-Wrap="false" HeaderStyle-Wrap="false"
Class="table table-striped table-bordered table-hover" OnRowCancelingEdit="GridView1_RowCancelingEdit"
OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating"
onrowdatabound="GridView1_RowDataBound" >
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="checkAll" runat="server" onclick="checkAll(this);" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" onclick="Check_Click(this)" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Calf ID">
<ItemTemplate>
<asp:Label ID="lbl_No" runat="server" Text='<%# Eval("CalfID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dam ID">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("DamID") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtDam" runat="server" Text='<%# Eval("DamID") %>' class="form-control"
Width="150"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Sire Name">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("SireName") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtSire" runat="server" Text='<%# Eval("SireName") %>' class="form-control"
Width="150"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date of Birth">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Eval("DOB") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtDate" runat="server" Text='<%# Eval("DOB") %>' class="form-control"
Width="150"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Calf Tag">
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Eval("CalfTag") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtCalfTag" runat="server" Text='<%# Eval("CalfTag") %>' class="form-control"
Width="150"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Gender">
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Eval("Gender") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtGender" runat="server" Text='<%# Eval("Gender") %>' class="form-control"
Width="150"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Weight">
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Eval("Weight") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtWeight" runat="server" Text='<%# Eval("Weight") %>' class="form-control"
Width="150"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Pen Name ">
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total Days ">
<ItemTemplate>
<asp:Label ID="Label70" runat="server" Text='<%# Eval("Days") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Action" ShowHeader="false">
<ItemTemplate>
<asp:LinkButton ID="btnedit" runat="server" CommandName="Edit" Text="Update" Visible ='<%# Convert.ToInt16(Eval("Days")) >= Convert.ToInt16(91) %>'></asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="btnupdate" runat="server" CommandName="Update" Text="Heifer"></asp:LinkButton>
<asp:LinkButton ID="btncancel" runat="server" CommandName="Cancel" Text="Dead"></asp:LinkButton>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#CCCCCC" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
Label lbl_No = GridView1.Rows[e.RowIndex].FindControl("lbl_No") as Label;////DamID,SireID,DOB,TagID,Gender,Calf_Pen,AnimalName,Bread,Company,AFrom,Type,LocNo,BStatus
con = new SqlDbConnect();
con.SqlQuery(@"select DamID,SireName,DOB,CalfTag,Gender,Calf_Pen,Animal_Name,Bread,Company,C_From,B_Type,Loctation,B_Status from tblCalf
where CalfID=@TId;");
con.Cmd.Parameters.Add(new SqlParameter("@TId", lbl_No.Text));
con.RdrEx();
while (con.Rdr.Read())
{
string Dam = con.Rdr[0].ToString();
string Sire = con.Rdr[1].ToString();
string DOB = con.Rdr[2].ToString();
string Tag = con.Rdr[3].ToString();
string Gen = con.Rdr[4].ToString();
string Pen = con.Rdr[5].ToString();
string Name = con.Rdr[6].ToString();
string Bread = "5"; // con.Rdr[7].ToString();
//string Company = con.Rdr[].ToString();
string AFrom = con.Rdr[8].ToString();
string Type = con.Rdr[9].ToString();
string LocNo = con.Rdr[10].ToString();
string Status = con.Rdr[11].ToString();
}
con.conClose();
con = new SqlDbConnect();
//con.SqlQuery(@"Insert into tblAnimal (DamID,SireID,BDate,TagID,Gender,PenID,AnimalName,BreadID,Company,AFrom,Type,LocNo,BStatus) values (@Dam,@Sire,@DOB,@Tag,@Gen,@Pen,@Name,@Bread,@Company,@From,@Type,@Loctation,@Status)");
con.SqlQuery(@"Insert into tblAnimal (DamID,SireID,BDate,TagID,Gender,PenID,AnimalName,BreadID,AFrom,Type,LocNo,BStatus) values (@Dam,@Sire,@DOB,@Tag,@Gen,@Pen,@Name,@Bread,@From,@Type,@Loctation,@Status)");
con.Cmd.Parameters.Add(new SqlParameter("@Dam", Dam.Text));
con.Cmd.Parameters.Add(new SqlParameter("@Sire", Sire.Text));
con.Cmd.Parameters.Add(new SqlParameter("@DOB", DOB.Text));
con.Cmd.Parameters.Add(new SqlParameter("@Tag", Tag.Text));
con.Cmd.Parameters.Add(new SqlParameter("@Gen", Gen.Text));
con.Cmd.Parameters.Add(new SqlParameter("@Pen", Pen.Text));
con.Cmd.Parameters.Add(new SqlParameter("@Name", Name.Text));
con.Cmd.Parameters.Add(new SqlParameter("@Bread", Bread.Text));
//con.Cmd.Parameters.Add(new SqlParameter("@Company", Company.Text));
con.Cmd.Parameters.Add(new SqlParameter("@From", AFrom.Text));
con.Cmd.Parameters.Add(new SqlParameter("@Type", Type.Text));
con.Cmd.Parameters.Add(new SqlParameter("@Loctation", LocNo.Text));
con.Cmd.Parameters.Add(new SqlParameter("@Status", Status.Text));
con.NonQueryEx();